akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> ab(N);
  for (ll i = 0; i < N; i++) {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab.begin(), ab.end());
  ll ans = 0;
  for (ll i = 0; i < N; i++) {
    if (M <= ab[i].second) {
      ans += ab[i].first * M;
      break;
    }
    M -= ab[i].second;
    ans += ab[i].first * ab[i].second;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li		int32_t
#define lli		long long
#define ulli unsigned long long

#define pn			printf("\n")
#define nl			cout<<'\n'
#define sf(N)       scanf("%lld",&N)
#define pf(N)       printf("%lld",N)
#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)	for(i=a;i<b;i++)
#define repr(i,a,b)	for(i=a;i>b;i--)
#define elif		else if
#define mset(a,b)	memset(a,b,sizeof(a))

#define pb		push_back
#define pob		pop_back
#define itr		iterator
#define sz()	size()
#define szof    sizeof
#define lb		lower_bound
#define ub		upper_bound
#define mp		make_pair
#define vlli    vector<lli>
#define plli	pair<lli,lli>
#define vplli	vector<plli >
#define Frst	first
#define Sec		second
#define Dup erase(unique(V.begin(),V.end()),V.end())

#define Inf     1000000000000000
#define mod		1000000007
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    opt;

    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    lli A,B,C;
    cin>>A>>B>>C;
    
    if(C>=A and C<=B)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    
    
    



 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int a = s.find("?");
  while(a != -1)
  {
    s.replace(a, 1, "D");
    a = s.find("?");
  }
  cout << s << endl;
}

Measured memory_bytes: 3760
cost, hate = map(int, input().split())
hate_num = list(map(int, input().split()))

hate_str = list(str(hate_num))
pay = cost
flag = True
while flag:
    pay_str = list(str(pay))
    for i in range(len(pay_str)):
        if set([pay_str[i]]) - set(hate_str) != set([pay_str[i]]):
            pay += 1
            flag = True
            break
        else:
            flag = False
print(pay)

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

int main() {
  int n = 0, x = 0;
  
  std::cin >> n;
  
  std::vector<int> a(n, 0); 
  
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  
  while (true) {
    for (int i = 0; i < n; i++) {
      if(a[i] % 2) {
        std::cout << x << std::endl;
        return 0;
      }
      a[i] /= 2;
    }
    x++;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from itertools import combinations as comb
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)
def y(f):
    if f:
        print('Yes')
    else:
        print('No')
def Y(f):
    if f:
        print('YES')
    else:
        print('NO')

m,d = map(int,input().split())
res = 0
for i in range(1, m + 1):
    for j in range(1, d + 1):
        if len(str(j)) != 2:
            continue
        a = j // 10
        b = j % 10
        if a * b != i or a < 2 or b < 2:
            continue
        # print(a, b, i)
        res += 1
print(res)

Measured memory_bytes: 5588
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
#define Would
#define you


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	a = min(b * 2, a);
	if (c % 500 != 0) { c += 500 - c % 500; }
	cout << (c / 1000)*a + (c % 1000) / 500 * min(a, b) << endl;
}



Measured memory_bytes: 3124
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

int main(){
  int N; cin >> N;
  set<ll> s; vector<ll> v; ll inp;
  
  for(int i=0; i<N; i++){
    cin >> inp;
    if(s.find(inp)!=s.end()){
      v.push_back(inp);
      s.erase(inp);
    }
    else{s.insert(inp);}
  }
  
  sort(v.begin(),v.end());
  
  if(v.size()<2){cout << 0;}
  else{cout << v[v.size()-1]*v[v.size()-2];}
  
  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<algorithm>
#include<bitset>
using namespace std;
int n,ans;
int main(){
  cin>>n;
  while(n>=3){
    ans++;n-=3;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

#ifndef __has_include
#define __has_include(x) (false)
#endif

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#endif



using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

template <class T, class BinaryOperation>
constexpr T fold(std::initializer_list<T> args, T init, BinaryOperation op)
{
	return std::accumulate(args.begin(), args.end(), init, op);
}

// numeric_low
namespace numeric
{
	template<class T>
	constexpr T gcd(const T x, const T y)
	{
		if (x < 0)return gcd(-x, y);
		if (y < 0)return gcd(x, -y);
		return (!y) ? x : gcd(y, x % y);
	}

	template<class T>
	constexpr T lcm(const T x, const T y)
	{
		if (x < 0)return lcm(-x, y);
		if (y < 0)return lcm(x, -y);
		return x * (y / gcd(x, y));
	}
}

// argsからハッシュ値を作成
template <class... Args>
std::size_t hash(Args... args)
{
	return fold({ static_cast<std::size_t>(args)... }, 0_sz,
		[](std::size_t seed, std::size_t x)
	{
		// uses magic number from boost
		return seed ^= x + 0x9e3779b9 + (seed << 6) + (seed >> 2);
	});
}

template <class Begin, class End>
void printAll(Begin beginIter, End endIter, std::string delimiter)
{
	for (auto iter{ beginIter }; iter != endIter; ++iter)
	{
		std::cout << *iter;
		if (std::distance(iter, endIter) != 1)
			std::cout << delimiter;
	}
}

template <class Container>
void printAll(const Container& c, std::string delimiter)
{
	printAll(std::cbegin(c), std::cend(c), delimiter);
}

template<class T>
void printAll(const std::initializer_list<T>& ini, std::string delimiter)
{
	printAll(ini.begin(), ini.end(), delimiter);
}

using ld = long double;

template <class T>
constexpr T nil = static_cast<T>(-1);

constexpr ll mod = 1000000007;

int main()
{
    using namespace std;

    int n, m, x, y;
    cin >> n >> m >> x >> y;

    vec<int> X(n);
    vec<int> Y(m);

    for (auto& e : X)
        cin >> e;
    for (auto& e : Y)
        cin >> e;
    
    X.push_back(x);
    Y.push_back(y);

    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    bool found{ false };

    for (int i = X.back() + 1; i <= Y.front(); ++i)
    {
        found |= true;
    }

    if (found)
        cout << "No War" << endl;
    else
        cout << "War" << endl;

	return 0;
}
 

Measured memory_bytes: 256
#abc155c
from collections import Counter

n=int(input())
s=[]
for i in range(n):
 s.append(input())
c=Counter(s)
mc=c.most_common()
s=[]
ref=mc[0][1]
i=0
while i<len(c):
 if mc[i][1]==ref:
  s.append(mc[i][0])
 i+=1
s.sort()
for i in range(len(s)):
 print(s[i])


Measured memory_bytes: 46084
#include<iostream>

using namespace std;

int main(){
	int n = 0, x = 0;
	
	while(1){

		cin >> n >> x;
		int cnt = 0;
		
		if( n == 0 && x == 0 ) break;
		
		for ( int i = 1; i <= (n-2); i++ ){
			for ( int j = i+1; j <= (n-1); j++ ){
				for ( int k = j+1; k <= n; k++ ){
					if( i + j + k == x ) 
						cnt ++;
				}
			}
		}
		cout << cnt << endl;
	}
	
	return 0;
}

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

struct RollingHash{
  int n;
  vector<long long> base, mod;
  vector<vector<long long>> hash, power;
  RollingHash(string s){
    base = {1009,9973};
    mod = {1000000007,1000000009};
    n = s.size();
    hash = vector<vector<long long>>(n+1,vector<long long>(2));
    power = vector<vector<long long>>(n+1,vector<long long>(2,1));
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < 2; ++j){
        hash[i+1][j] = (hash[i][j]+s[i])*base[j]%mod[j];
        power[i+1][j] = power[i][j]*base[j]%mod[j];
      }
    }
  }
  vector<long long> get(int l, int r){//[l,r)
    vector<long long> ret(2);
    for(int i = 0; i < 2; ++i)
      ret[i] = ((hash[r][i]-hash[l][i]*power[r-l][i])%mod[i]+mod[i])%mod[i];
    return ret;
  }
};

struct RollingHash_64{
  int n;
  unsigned long long base;
  vector<unsigned long long> hash, power;
  RollingHash_64(string s){
    base = 1e9 + 7;
    n = s.size();
    hash.assign(n+1,0);
    power.assign(n+1,1);
    for(int i = 0; i < n; ++i){
      hash[i+1] = (hash[i]+s[i])*base;
      power[i+1] = power[i]*base;
    }
  }
  unsigned long long get(int l, int r){//[l,r)
    return hash[r]-hash[l]*power[r-l];
  }
};

int main(){
  int N;
  cin >> N;
  vector<string> S(2*N);
  for(int i = 0; i < N; ++i){
    cin >> S[i];
    S[i] += S[i];
    S[i+N] = S[i];
  }
  vector<RollingHash_64> H, V;
  int N_ = 2*N;
  for(int i = 0; i < N_; ++i) V.emplace_back(S[i]);
  for(int j = 0; j < N_; ++j){
    string s;
    for(int i = 0; i < N_; ++i){
      s += S[i][j];
    }
    H.emplace_back(s);
  }
  int ans = 0;
  for(int i = 0; i < N; ++i){
    bool f = true;
    for(int k = 0; k < N; ++k){
      auto v = V[i+k].get(0,N), h = H[k].get(i,i+N);
      if(v != h){
        f = false;
        break;
      }
    }
    if(f) ans += N;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
 
int run_test(){
      int n;
      cin >> n;
      ll arr[n];
      for(int i=0; i<n; i++){
            cin >> arr[i];
      }
      ll ans = 0;
      for(int i=0; i<n-1 ; i++){
            if(arr[i+1] < arr[i]){
                  ans += arr[i] - arr[i +1];
                  arr[i+1] = arr[i]; 
            }
      }
      cout << ans;
      return 0;
}
 
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}


Measured memory_bytes: 5228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

double x;
LL s, ans, maxn = 1e10;
int n, cnt[505][505];

int main() {
	cin>>n;
	rep(i, 1, n) {
		cin>>x;
		s = (long long) (x*maxn + 0.5);
		int a = 0, b = 0;
		while(s%2 == 0) s /= 2, a++;
		while(s%5 == 0) s /= 5, b++;
		a = min(a, 20), b = min(b, 20);
		ans += cnt[20 - a][20 - b];
		rep(j, 0, a)
		    rep(k, 0, b)
		        cnt[j][k]++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3740
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<pair<int, int>, int>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    vector<ll> SUM(n + 10, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        SUM[max(0ll, i - a[i])]++;
        SUM[min(n, i + a[i] + 1)]--;
    }
    for (int i = 0; i < n; i++)
    {
        SUM[i + 1] += SUM[i];
    }
    int rest = 0;
    for (ll i = 0; i < min(100ll, k - 1); i++)
    {
        ll MIN = 1001001001;
        vector<ll> SUM1(n + 10, 0);
        for (ll j = 0; j < n; j++)
        {
            SUM1[max(0ll, j - SUM[j])]++;
            SUM1[min(n, j + SUM[j] + 1)]--;
        }
        for (int j = 0; j < n; j++)
        {
            SUM1[j + 1] += SUM1[j];
            MIN = min(MIN, SUM[j + 1]);
        }
        if (MIN >= n)
        {
            rest = k - 1 - i;
            break;
        }
        swap(SUM, SUM1);
    }
    for (int i = 0; i < n; i++)
    {
        SUM[i] += n * rest;
    }
    for (int i = 0; i < n; i++)
    {
        cout << SUM[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 7956
#include<string>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<queue>
#include<iostream>
using namespace std;
const int N= 101;
int a[N],b[N];
int main(){
	int n;
	cin >>n;
	for(int i=1;i<n;i++)
		cin >>b[i];
	long long sum=b[n-1];
	for(int i=n-1;i>=1;i--){
		a[i]=b[i];
		if(i>=2){
			if(b[i-1]<a[i]){
			a[i]=b[i-1];
			
		}
		}
		
		sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
} 
	
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

// 各桁の和を計算する関数
int findSumOfDigits(int n){
    int sum = 0;
    while (n > 0) { // n が 0 になるまで
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    int fx = findSumOfDigits(n);
    
    int r = n % fx;
    if(!r)  cout << "Yes" << endl;
    else    cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

#define ld long double
#define ll long long int
#define endl '\n'
#define check_time() cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1e9+7
#define INF 0x3f3f3f3f
#define maxarr(A,n) *max_element(A,A+n) 
#define minarr(A,n) *min_element(A,A+n);

int main()
{
	fastio();
	ll N,M,a,b,i;
	ll ans=0;
	cin>>N>>M;
	ll H[N+1];
	ll Noroads[N+1]={0};

	set<int> s_imp;
	set<int> s_p;

	for(i=1;i<=N;i++)
		cin>>H[i];
	for(i=0;i<M;i++)
	{
		cin>>a>>b;
		Noroads[a]++;
		Noroads[b]++;
		if(H[a]>H[b])
		{
			auto pos1= s_imp.find(a);
			if(pos1==s_imp.end())
				s_p.insert(a);

			auto pos2= s_p.find(b);
			if(pos2!=s_p.end())
				s_p.erase(b);
			s_imp.insert(b);
		}
		else if(H[b]>H[a])
		{
			auto pos1= s_imp.find(b);
			if(pos1==s_imp.end())
				s_p.insert(b);

			auto pos2= s_p.find(a);
			if(pos2!=s_p.end())
				s_p.erase(a);
			s_imp.insert(a);
		}
		else
		{
			auto pos1= s_p.find(a);
			auto pos2= s_p.find(b);
			if(pos1!=s_p.end())
				s_p.erase(a);
			if(pos2!=s_p.end())
				s_p.erase(b);
			s_imp.insert(a);
			s_imp.insert(b);
		}
	}

	for(i=1;i<=N;i++)
	{
		if(Noroads[i]==0)
			ans++;
	}
	ans+=s_p.size();
	cout<<ans<<endl;
	return 0;   
}   


Measured memory_bytes: 9184
[H,N]=[int(i) for i in input().split()]
A=[0 for i in range(N)]
B=[0 for i in range(N)]
for n in range(N):
  [A[n],B[n]]=[int(i) for i in input().split()]
k=H+max(A)+1
DP=[100000000 for i in range(k)]
DP[0]=0
for n in range(N):
  for h in range(k):
    if h-A[n]>-1:
    	if DP[h-A[n]]+B[n]<DP[h]:DP[h]=DP[h-A[n]]+B[n]
print(min(DP[H:]))

Measured memory_bytes: 41708
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

long modpow(long a, long n, long mod){
  long size;
  for (long i = 1; ; i++) {
    if (pow(2,i) > n) {
      size = i;
      break;
    }
  }
  long bit[size];
  bit[0] = n;
  for (long i = 1; i < size; i++) {
    bit[i] = bit[i-1]/2;
    bit[i-1] %= 2;
  }
  long powa[size];
  powa[0] = a;
  for (long i = 1; i < size; i++) {
    powa[i] = powa[i-1]*powa[i-1];
    powa[i] %= mod;
  }
  long answer = 1;
  for (long i = 0; i < size; i++) {
    if (bit[i] == 1) {
      answer *= bit[i]*powa[i];
      answer %= mod;
    }
  }
  return answer;
}

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return 1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  char s[200001];
  scanf("%s", s);
  long length = strlen(s);
  long modlist[length];
  modlist[length-1] = s[length-1]-'0';
  for (long i = length-2; i >= 0; i--) {
    modlist[i] = modlist[i+1]+(s[i]-'0')*modpow(10,length-1-i,2019);
    modlist[i] %= 2019;
  }
  qsort(modlist, length, sizeof(long), cmpnum);
  long answer = 0;
  long count = 1;
  for (long i = 1; i < length; i++) {
    if (modlist[i] == modlist[i-1]) {
      count++;
    } else {
      if (modlist[i-1] == 0) {
        count++;
      }
      answer += count*(count-1)/2;
      count = 1;
    }
  }
  if (modlist[length-1] == 0) {
    count++;
  }
  answer += count*(count-1)/2;
  printf("%ld\n", answer);

  return 0;
}

Measured memory_bytes: 5420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
// #include <tuple>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
 
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 60) - 1;
const ll MOD = 1e9 + 7;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3
 
int n, m, r;
ll dp[210][210];
vector<int> vi;
 
int main() {
	rep(i, 210)rep(j, 210) {
		if (i != j)dp[i][j] = INF;
	}
	cin >> n >> m >> r;
	rep(i, r) {
		int num;
		cin >> num;
		num--;
		vi.push_back(num);
	}
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		dp[a][b] = c;
		dp[b][a] = c;
	}
	rep(k, n) {
		rep(i, n) {
			rep(j, n) {
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
    ll ans = INF;
    sort(vi.begin(), vi.end());
	do {
		bool f = 1;
		ll num = 0;
		rep(i, vi.size() - 1) {
			if (dp[vi[i]][vi[i + 1]] > 100000 * 200)f = 0;
			num += dp[vi[i]][vi[i + 1]];
		}
		if(f)ans = min(ans, num);
	} while (next_permutation(ALL(vi)));
	cout << ans << endl;
}

Measured memory_bytes: 640
ope = {"+": lambda a, b: b + a,
	   "-": lambda a, b: b - a,
	   "*": lambda a, b: b * a}
stack = []

for c in input().split():
	if c in ope:
		stack.append(ope[c](stack.pop(), stack.pop()))
	else:
		stack.append(int(c))

print(stack[-1])

Measured memory_bytes: 7740
N = int(input())
S = list(input())
shiro_sum = [0] * (N+1)
kuro_sum = [0] * (N+1)
for i in range(N):
    if S[i] == '.':
        shiro_sum[i+1] = shiro_sum[i] + 1
    else:
        shiro_sum[i+1] = shiro_sum[i] + 0

    if S[i] == '#':
        kuro_sum[i+1] = kuro_sum[i] + 1
    else:
        kuro_sum[i+1] = kuro_sum[i] + 0

res = 10**9
# i == 0
for i in range(N+1):
    tmp = 0
    # leftを全て白に
    # 左側にある黒の数を数える。
    tmp += kuro_sum[i] - kuro_sum[0]

    # rightを全て黒に
    # 右側にある白を数えて、全体の数から白の合計を消す
    tmp += shiro_sum[N] - shiro_sum[i]
    res = min(res, tmp)
print(res)

Measured memory_bytes: 20448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		if(n <= 9) {
			System.out.println("Yes");
			return;
		}
		for(int i = 2; i <= 9; i++) {
			if(n % i == 0 && n / i <= 9) {
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");
	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PI  3.14159265358979323846
#define lp(i,n) for(int i = 0; i <n;i++)
#define rlp(i,n) for(int i = int(n);i >= 0;i--)
#define range1(i,a,b,c) for(int i = int(a);i <= int(b);i+=int(c))
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define fr first
#define sc second
#define sz(v) ((int)((v).size()))
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
typedef pair<int, int> pii;
template<class T> using ordered_set=tree<T,
null_type,
less<T>,
rb_tree_tag,
tree_order_statistics_node_update>;
const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;
int dx[] = {0,0,-1,1};
int dy[] = {1,-1,0,0};
void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
vi a;
void _run(){
    int n;
    cin>>n;
    a.resize(n);
    lp(i,n){
        cin>>a[i];
    }
    ll ans =0;
    for(int i=1;i<n;i++){
        if(a[i-1]>a[i]){
            int temp = a[i-1]-a[i];
            a[i]=temp+a[i];
            ans+=(ll)temp;
        }
    }
    cout<<ans<<endl;
}
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int t=1;
    // scanf("%d",&t);
    while(t--)_run();
    
    return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,x) for(int i=0;i<x;++i)
 
int main()
{
    int N;cin>>N;
    vector<int> a(N);
    rep(i,N)cin>>a[i];

    int mi = 1e9;

    rep(i, 401) {
        int sum = 0;

        rep(j, N) {
            int v = -200 + i - a[j];
            sum += v*v;
        }

        mi = min(mi, sum);
    }

    cout << mi << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main( void ) 
{
	int a,b;
	int  res=0;
	int i;	
	while( EOF != scanf( "%d%d", &a, &b ) ) {
		res=a+b;
		a=10;
		for( i=1; ; i++ ) {
			b=res-a;
			if( 0<=b ) {
				a*=10;			
			} else {
				break;
			}
		}
		printf( "%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
// #include <bits/stdc++.h> all

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int r; cin >> r;
  cout << r*r << endl;

  return 0;
}

Measured memory_bytes: 256
local mmi = math.min
local sn = io.read()
local n = #sn
local t = {}
for i = 1, n do
  t[i] = tonumber(sn:sub(i, i))
end
local p1, p2 = 1, 0
for i = 1, n do
  local np1 = 1000000007
  if i ~= n and 0 < t[i + 1] then
    np1 = mmi(p1 + 9 - t[i], p2 + t[i] + 1)
  end
  local np2 = mmi(p1 + 10 - t[i], p2 + t[i])
  p1, p2 = np1, np2
end
print(mmi(p1, p2))


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


int main(){
  int N;
  cin >> N;
  vector<int>p(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
  }
  int num=0;
  for(int i=0;i<N;i++){
    if((i+1)!=p.at(i)){
      num++;
    }
  }
  if(num<=2){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" <<endl;
  }
  
  
}
      


Measured memory_bytes: 256
from heapq import heappop,heappush

n,m = map(int,input().split())

AB = [[int(i) for i in input().split()] for j in range(n)]

#ab.sort()

AB = sorted(AB, key=lambda x: x[0])

#print(ab)

tmp = 0
hq = []
ans = 0

for i in range(1,m+1):
    while tmp <= n-1 and AB[tmp][0] <= i:
        heappush(hq,-AB[tmp][1])
        tmp += 1
    if len(hq) > 0:
        ans += -heappop(hq)
        
print(ans)

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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n,n1,n2;
	cin >> n;
	n1 = n / 2;
	n2 = n % 2;
	cout << n1 + n2 << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
int n;
int ans=0;
typedef vector<int> vi;
int main()
{
  vi a(4,0);
  vi b(2,0);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  cin >> b[0] >> b[1];
  sort(a.begin(),a.end(),greater<int>());
  sort(b.begin(),b.end(),greater<int>());
  int ans=0;
  for(int i=0;i<3;i++)
    {
      ans+=a[i];
    }
  ans+=b[0];
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3148
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

const int MAX_N = (int)1e5 + 77;
const int MAX_LOG = 50;

int nxt[MAX_LOG][MAX_N], n, cnt[MAX_N];

void solve()
{
	string s;
	cin >> s;

	n = len(s);

	for(int i = 0; i < n; ++i)
		nxt[0][i] = (s[i] == 'R' ? +1 : -1) + i;

	for(int log = 1; log < MAX_LOG; ++log)
	{
		for(int i = 0; i < n; ++i)
			nxt[log][i] = nxt[log - 1][nxt[log - 1][i]];
	}

	for(int i = 0; i < n; ++i)
		++cnt[nxt[MAX_LOG - 1][i]];

	for(int i = 0; i < n; ++i)
		cout << cnt[i] << " ";

	cout << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 20560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n>> m;
    vector<int>a(m);
    vector<ll>answer(n+10,0);
    REP(i,m){
        cin >> a[i];
        answer[a[i]]=-1;
    }

    answer[0]=1;

    REP(i,n){
        if(answer[i]==-1)continue;
        if(answer[i+1]!=-1){
            answer[i+1]=(answer[i+1]+answer[i])%MOD;
        }
        if(answer[i+2]!=-1){
            answer[i+2]=(answer[i+2]+answer[i])%MOD;
        }
    }

    cout << answer[n] << endl;

    return 0;
}

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define mod 1000000007LL
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res + m) * ( a + m) % m;
        a = a * a % m;
        b >>= 1;
    }
    return (res + m) % m;
}

long long mul(long long a, long long b){
    a = (a + mod) % mod;
    b = (b + mod) % mod;
    return ((a + mod) * (b + mod))%mod;
}
long long add(long long a, long long b){
    a += mod;
    b += mod;
    return (a + b)%mod;
}
ll inv(ll x){
    return binpow(x, mod - 2, mod);
}
#define int ll
signed main()
{
    ll d, t, s;
    cin >> d >> t >> s;
    if(d <= t * s)
        cout << "Yes";else
        cout << "No";
}

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

using namespace std;
typedef unsigned long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll M;
    cin >> M;

    cout << 24 - M + 24<< endl;

}

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

int main()
{
	int n, m;
	std::cin >> n >> m;
	for (int i = 0; i < m + 2; ++i)
		std::cout << "#";
	std::cout << "\n";
	
	std::cin.ignore(32767, '\n');
	while(n--)
	{
		std::string str;
		std::getline(std::cin, str);
		std::cout << "#" << str << "#\n";
	}
 	for (int i = 0; i < m + 2; ++i)
		std::cout << "#";
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>      //std::stack
#include <string>
#include <stdlib.h>
using namespace std;
std::stack<int> myStack;

int data_pop(void)
{
	int data = myStack.top();
	myStack.pop();
	return data;
}

void calcAndPush(string container)
{
    int data01, data02;
	if(container == "+")             //addition
	{
		data01 = data_pop();
		data02 = data_pop();
		myStack.push(data01+data02);
	}
	else if(container == "-")         //subtraction
	{
		data01 = data_pop();
		data02 = data_pop();
		myStack.push(data02-data01);
	}
	else if(container == "*")       //multiplication
	{
		data01 = data_pop();
		data02 = data_pop();
		myStack.push(data01*data02);
	}
	else
	{
		myStack.push(atoi(container.c_str()));
	}
	return;
}

int main(void)
{
	string container;
	int count = 0;			// mojisuu
	int containerSize = 0;  // stack yousosuu

	while(cin >> container)
	{
		count++;
		containerSize = myStack.size();
		if(count > 2)
		{
			if(containerSize >= 2)
			{
				calcAndPush(container);
			}
			else
			{
				myStack.push(atoi(container.c_str()));
			}
            
		}
		else
		{
			myStack.push(atoi(container.c_str()));
		}
	}
   
	//result
	if(containerSize < 2)
	{
		myStack.pop();			//Exile the last element
	}
	cout << myStack.top() << endl;		//Calculation result
	return 0;
}

Measured memory_bytes: 3164
#!/usr/bin/env python3
import sys
import math

def solve(K: int):
    result = 0
    for a in range(1, K+1):
        for b in range(1, K+1):
            if math.gcd(a, b) == 1:
                result += K
                continue
            for c in range(1, K+1):
                result += math.gcd(a, math.gcd(b, c))
    print(result)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    solve(K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
#define pie 3.14159265358979323846
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
bool greater_pair(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first!=b.first){
        return a.first>b.first;
    }else{
        return a.second>b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    ll X;
    cin>>X;
    ll ans=0;
    ll yokin=100;
    while(yokin<X){
        yokin+=yokin/100;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		int z=1,ans=1,x=1;
		String a=S.substring(0,1);
		String b="";
		while(z<S.length()){
			b=S.substring(z,z+1);
			if(a.equals(b)){
				if(z>=S.length()-1)
					ans--;
				if(z!=S.length()-1)
					b=S.substring(z,z+2);
				z++;
			}
			a=b;ans++;z++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 36460
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input!{
        n: usize,
        k: usize,
    }

    let mut ret = vec![false; n];

    for i in 0..k{
        input!{
            d: usize,
        }
        input!{
            sn: [Usize1; d],
        }
        for s in sn{
            if !ret[s]{
                ret[s] = true;
            }
        }
    }
    let mut count = 0;
    for s in ret{
        if !s{
            count += 1;
        }
    }

    println!("{:?}",count);
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N,K;
  cin >> N >> K;
  vi h(N);
  rep(i,N) {
    cin >> h[i];
  }
  sort(rng(h));
  int ans = INF;
  rep(i,N-K+1) {
    ans = min(ans,h[i+K-1]- h[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  char a;
  cin>>a;
  if(a=='A'){
    cout<<'T'<<endl;
  }
   if(a=='T'){
    cout<<'A'<<endl;
   }
  
   if(a=='C'){
    cout<<'G'<<endl;
  }
   if(a=='G'){
    cout<<'C'<<endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
typedef long long int ll;


int main()
 {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
   fast;
  
     int k;cin>>k;
     string s;cin>>s;
     string res="";
     int n=s.length();
     if(k>=n)
     {
         for(int i=0;i<n;i++){
             res+=s[i];
         }
         cout<<res<<endl;
     }
     else {
         for(int i=0;i<k;i++){
             res+=s[i];
         }
         cout<<res<<"..."<<endl;
     }



	return 0;
}

Measured memory_bytes: 3640
def bfs(x, visited, order):
  if visited[x]:
    return
  visited[x] = True
  for to in edges[x]:
    bfs(to, visited, order)
  order.append(x)

def bfs_rev(x):
  if visited[x]:
    return []
  visited[x] = True
  ret = [x]
  for to in rev_edges[x]:
    ret += bfs_rev(to)
  return ret

n = int(input())
edges = [[] for _ in range(200)]
rev_edges = [[] for _ in range(200)]
for _ in range(n):
  u, s, d = input().split()
  u = int(u) - 1
  d = int(d) - 1 + 100
  if s == "lock":
    edges[d].append(u)
    rev_edges[u].append(d)
  else:
    edges[u].append(d)
    rev_edges[d].append(u)

order = []
visited = [False] * 200
for i in range(200):
  if not visited[i]:
    bfs(i, visited, order)

order.reverse()
visited = [False] * 200
for i in order:
  if not visited[i]:
    if len(bfs_rev(i)) >= 2:
      print(1)
      break
else:
  print(0)


Measured memory_bytes: 5724
k, n = gets.chomp.split.map(&:to_i)
aryA = gets.chomp.split.map(&:to_i)

aryDistances = []
aryDistances.push aryA[0] + (k - aryA[n-1])
for i in 1..(n-1) do
    aryDistances.push aryA[i] - aryA[i-1]
end

puts k - aryDistances.max


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

int main() {
    int H,W; cin >> H >> W;
    int S[H+10][W+10] = {0};

    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            char C; cin >> C;
            if(C == '#') S[i][j] = 0;
            else if(C == '.') S[i][j] = 1;
        }
    }

    //頂点番号
    int number = 1;
    int N = H*W;
    int MAX = 0;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N+5);
    for(int i=1; i<=H; i++) {
        for(int j=1; j<=W; j++) {
            if(S[i][j] == 1) { 
                if(S[i-1][j] == 1) G[number].push_back(number-W); 
                if(S[i+1][j] == 1) G[number].push_back(number+W); 
                if(S[i][j-1] == 1) G[number].push_back(number-1); 
                if(S[i][j+1] == 1) G[number].push_back(number+1); 
            }
            number++;
        }
    }

    for(int i=1; i<=N; i++) {
    // BFS のためのデータ構造
    vector<int> dist(N+5, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 i を初期ノードとする)
    dist[i] = 0;
    que.push(i); // i を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 1 からの距離を見る)
    for (int v = 1; v <= N; ++v) {
        if(MAX < dist[v]) MAX = dist[v];
        //cout << v << ": " << dist[v] << endl;
        }
    }
    cout << MAX << endl;
}

Measured memory_bytes: 3644
// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include "stdio.h"
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <string>
#include <iostream>
#include <vector>
#include <sstream>

using namespace std;

static const int IntMax = 1000000000;

void outputA(const std::vector<int>& A)
{
	const int N = A.size();
	cout << A.front();
	for (int k = 1; k != N; ++k) {
		cout << " " << A.at(k);
	}
	cout << endl;
}

int main()
{
	//const int numberOfValues = getIntFromStringInput(cin);
	int N; cin >> N;
	std::vector<int> A(N);
	for (int& i : A) cin >> i;

	for (int i = 1; i != N; ++i) {
		outputA(A);
		int v = A.at(i);
		int j = i - 1;
		while (j >= 0 && A.at(j) > v) {
			A.at(j + 1) = A.at(j);
			--j;
		}
		A.at(j + 1) = v;
	}
	outputA(A);

	return 0;
}


Measured memory_bytes: 3092
import sys
input=sys.stdin.readline
n=int(input())
F=[list(map(int,input().split())) for i in range(n)]
P=[list(map(int,input().split())) for i in range(n)]
ans=-10**9
for i in range(1,2**10):
  tmp=0
  for j in range(n):
    f,p=F[j],P[j]
    cnt=0
    for k in range(10):
      if (i>>k)&1 and f[k]:
        cnt+= 1
    tmp+=p[cnt]
  ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 3188
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
ans = 1
if a[-1] == 0:
    print(0)
    exit()
for i in a:
    ans *= i
    if ans > 10**18:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 22620
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Mod_nCr {
  private:
    vector<long long> fac, finv, inv;
    const int MOD = 1'000'000'007;

  public:
    Mod_nCr(int N) {
        fac.resize(N);
        finv.resize(N);
        inv.resize(N);
        fac[0]  = 1;
        fac[1]  = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1]  = 1;
        for (int i = 2; i < N; i++) {
            fac[i]  = fac[i - 1] * i % MOD;
            inv[i]  = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    long long nCr(int n, int r) {
        if (n < r || n < 0 || r < 0)
            return 0;
        return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
    }
};

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

    int N, K;
    cin >> N >> K;

    ll ans    = 0;
    int red   = N - K + 1;
    auto mncr = Mod_nCr(N);

    FOR(i, 1, K + 1) {

        ll a   = mncr.nCr(red, i);
        ll b   = mncr.nCr(K - 1, i - 1);
        ll ans = a * b;
        MOD(ans);
        std::cout << ans << '\n';
    }

    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;

char p[5][5];

int main(){
//    freopen("test.txt","r",stdin);
    for (int i = 1; i <=3 ; i++) {
        for (int j =1 ; j <= 3; j++) {
            cin >> p[i][j];
        }
    }
    if ( p[1][1] == p[2][3] && p[1][2] == p[2][2] && p[1][3] == p[2][1]) {
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}


Measured memory_bytes: 256
for _ in range(int(input())):
    s=input()
    l=set()
    for i in range(1,len(s)+1):
        e=[
            s[:i]+s[i:],
            s[:i]+s[i:][::-1],
            s[:i][::-1]+s[i:],
            s[:i][::-1]+s[i:][::-1],
            s[i:]+s[:i],
            s[i:]+s[:i][::-1],
            s[i:][::-1]+s[:i],
            s[i:][::-1]+s[:i][::-1]
        ]
        l=l|set(e)
    print(len(l))    



Measured memory_bytes: 5636