akhauriyash/Code-Regression huggingface dataset:
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define REP_AB(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define REP_IN(i, n, x) for (ll i = 0; i < n; i++)in>>x;
#define REP_OUT(i, n, x) for (ll i = 0; i < n; i++)out<<x<<endl;
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
#define endl '\n'
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    //vector<ll> X(N);
    //string s;
    //in >> s;
    //vector<string> s;
    //s.resize(N);
    ll K,a;
    in >> K;
    ll ans=0;
    
    
    REP_AB(i,1,K+1){
        REP_AB(j,1,K+1){
            a=gcd(i,j);
            REP_AB(n,1,K+1){
                ans+=gcd(a,n);
            }
        }
    }
    out<<ans<<endl;
    
    
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string n; cin>>n;
    if (n[0]==n[1]&&n[1]==n[2]) cout<<"Yes"<<endl;
    else if(n[1]==n[2]&&n[2]==n[3]) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
mod = 10**9+7
def cmb(n,r):
  c=1
  for i in range(r):
    c = (c*(n-i)*pow(i+1,mod-2,mod))%mod
  return c

na = cmb(n,a)
nb = cmb(n,b)
print((pow(2,n,mod)-1-na-nb)%mod)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

const int N=100500;
int OO=INT_MAX;
int n,a[N],b[N],c[N];
int mem[N][4];
int many=0;

int solve(int idx,int last)
{
    if(idx==n)
        return 0;
    if(mem[idx][last]!=-1)
        return mem[idx][last];
    int op1=-OO,op2=-OO;
    if(last==1)
    {
        op1=solve(idx+1,2)+b[idx];
        op2=solve(idx+1,3)+c[idx];
    }
    if(last==2)
    {
        op1=solve(idx+1,1)+a[idx];
        op2=solve(idx+1,3)+c[idx];
    }
    if(last==3)
    {
        op1=solve(idx+1,1)+a[idx];
        op2=solve(idx+1,2)+b[idx];
    }
    return mem[idx][last] = max(op1,op2);
}

int main() {

    cin>>n;
    for(int i=0;i<n;++i)
    {
        mem[i][1]=-1;
        mem[i][2]=-1;
        mem[i][3]=-1;
        cin>>a[i]>>b[i]>>c[i];
    }
    int fcall,scall,thcall;

    fcall=solve(1,1)+a[0];
    scall=solve(1,2)+b[0];
    thcall=solve(1,3)+c[0];

    cout<< max(fcall,max(scall,thcall));

	return 0;
}


Measured memory_bytes: 7680
n,a,b,c,d = map(int,input().split())
s = input()

ans = 'Yes'
if '##' in s[a-1:c]:
  ans = 'No'  
if '##' in s[b-1:d]:
  ans = 'No'
  
if c > d:
  if '...' not in s[b-2:d+1]:
    ans = 'No'

print(ans)    

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n,k;
  cin >> n >> k;
  int r,s,p;
  cin >> r >> s >> p;
  string t;
  cin >> t;
  int ans = 0;
  vector<int> dp(n);
  rep(i,k) {
    if(t[i] == 'r') ans += p;
    if(t[i] == 's') ans += r;
    if(t[i] == 'p') ans += s;
    dp[i] = 1;
  }
  for(int i = k; i < n;i++) {
    if(t[i] == t[i-k] && dp[i-k] == 1) {
      dp[i] = 0;
    }else {
      if(t[i] == 'r') ans += p;
      if(t[i] == 's') ans += r;
      if(t[i] == 'p') ans += s;
      dp[i] = 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896
/* Author : Pranav Deshmukh
            PICT,Pune
   Stay Focused!
*/

#include<bits/stdc++.h>
using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define int             long long
#define float           double
#define ms(s, n) 		memset(s, n, sizeof(s))
#define dip(type,var)   type var; cin>>var;
#define dipi(x)         int x; cin>>x;
#define dipi2(x,y)      int x,y; cin>>x>>y;
#define w(x)            int x; cin>>x; while(x--)
#define mka(type,arr,n) type *arr=new type[n];
#define fo(i,n)         for(int i=0;i<n;i++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define endl            "\n"
#define f               first
#define s               second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	c_p_c();
	dipi(x);
	if (x >= 30)
		cout << "Yes";
	else
		cout << "No";
	cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <string.h>
using namespace std;
int main(void){

    string S;
    int K;
    cin>>K>>S;
    if(S.size()<=K){
        cout<<S<<endl;
    }
    else{
        S.erase(K, S.size());
        S+="...";
        cout<<S<<endl;
    }
    
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
#define int long long
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
const long double pI = 2*acos(0.0);

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int r; cin >> r;
	cout << 2.0*r*pI;
}

Measured memory_bytes: 3744
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(n, k, p):
    return sum(sorted(p)[:k])


if __name__ == "__main__":
    n, k = arr_in()
    p = arr_in()
    out(solve(n, k, p))

Measured memory_bytes: 62560
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x) // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
    {
        cout << "vowel" << endl;
    }
    else
    {
        cout << "consonant" << endl;
    }
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s; cin >> s;
    int n = s.size();

    int cntA = 0;
    int cntB = 0;
    int cntC = 0;
    REP(i, n) {
        if (s[i] == 'a') cntA++;
        if (s[i] == 'b') cntB++;
        if (s[i] == 'c') cntC++;
    }

    if (abs(cntA - cntB) <= 1 && abs(cntA - cntC) <= 1 && abs(cntB - cntC) <= 1)
        cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int n;
string b;

int calc(string s) {
  int res = 0;
  for (char c : s) {
    res <<= 1;
    if (c == '1') res++;
  }
  return res;
}

string conv(int n, int sp = 0) {
  string res = "";
  while (n > 0) {
    res = (n & 1 ? "1" : "0") + res;
    n >>= 1;
  }
  while (res.size() < sp) res = "0" + res;
  return res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  while (cin >> n, n) {
    cin >> b;
    int es = 0;
    string bs = b;
    while (n > 0) {
      string bb = "1" + b;
      bb = bb.substr(0,max(0LL,(int)bb.size()-es));
      int P = calc("1"+bs);
      int Q = calc(bb);
      if (Q == 0) break;
      int k = (POW(53)-P+Q-1)/Q;
      if (n < k) {
        int R = P+Q*n;
        bs = conv(R).substr(1);
        break;
      }
      int R = P+Q*k;
      R >>= 1;
      bs = conv(R).substr(1);
      es++;
      n -= k;
    }
    cout << conv(es,12)+bs << endl;
  }

  return 0;
}


Measured memory_bytes: 3180
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N; long long K; cin >> N >> K;
    map<int, long long> num;
    for (int i = 0; i < N; i++) {
        int a; long long b; cin >> a >> b;
        num[a] += b;
    }

    long long rem = K;
    for (auto i = num.begin(); i != num.end(); i++) {
        if (rem <= i->second) {
            cout << i->first << endl;
            break;
        }
        rem -= i->second;
    }

    return 0;
}

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

int main (){
  int l,maxe = -1,mine = 128;
  for (int i = 0;i < 5;i++){
    cin >> l;
    maxe = max(maxe,l);
    mine = min(mine,l);
  }
  cin >> l;
  if (l < maxe-mine)cout << ":(" << endl;
  else cout <<"Yay!" << endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
s = list(input())
m = 0
k = 0
for i in range(n):
 
  if s[i] == 'c':
    print('No')
  elif s[i] == 'a':
    if m < a + b:
      print('Yes')
      m += 1 
    else:
      print('No')
  elif s[i] == 'b':
    if m < a + b and k < b:
      print('Yes')
      m += 1
      k += 1
    else:
      print('No')

Measured memory_bytes: 10008
#include <iostream>

using namespace std;

int max(int a, int b){
    if (a >= b) {
        return a;
    }else{
        return b;
    }
}

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

    int m1;
    m1 = max(a, max(b, c));

    cout << m1 * 9 + a + b + c << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
string s;
int k;
int INF=1000000000;
int dh[4]={0,1,0,-1};
int dw[4]={1,0,-1,0};

int main(){
    int n;cin>>n;
    vector<pair<ll,ll> > v(n);
    for(int i=0;i<n;i++){
        int x,l;
        cin>>x>>l;
        v[i]=make_pair(x+l,x-l);
    }
  sort(v.begin(),v.end());
    ll now=v[0].first;
    int ans=1;
    rep(i,1,n){
        if(now<=v[i].second){
            ans++;
            now=v[i].first;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <stdio.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    if(c > (a - b)){
        cout << c - (a - b) << endl;
    }
    else{
        cout << 0 << endl;
    }


}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#define pb push_back 
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define MOD 1000000007
using namespace std;

int main() {
    int n;
    string s1, s2;
    long long ans = 1;
    cin >> n;
    cin >> s1 >> s2;
    string left;
    if (s1[0] == s2[0]) {
        ans *= 3;
        left = "one";
        for (int i = 1; i < n; i++) {
            if (s1[i] == s2[i]) {
                if (left == "one")ans *= 2;
                ans %= MOD;
                left = "one";
            }
            else {
                if (left == "one")ans *= 2;
                else ans *= 3;
                ans %= MOD;
                left = "two";
                i++;
            }
        }
    }
    else {
        ans *= 6;
        left = "two";
        for (int i = 2; i < n; i++) {
            if (s1[i] == s2[i]) {
                if (left == "one")ans *= 2;
                ans %= MOD;
                left = "one";
            }
            else {
                if (left == "one")ans *= 2;
                else ans *= 3;
                ans %= MOD;
                left = "two";
                i++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

char shop[26];
char billboard[100][101];

int search(int idx,int line,int current,int interval){
	int i,count=0;
	if(current==strlen(shop)) {
		return 1;
	}
	for(i=idx+1;i<strlen(billboard[line]);i++){
		if(shop[current]==billboard[line][i] && (interval==i-idx || current==1)) count=max(count,search(i,line,current+1,i-idx));
	}
	return count;
}

int main(){
	int n,i,j,a,b=0;

	scanf("%d",&n);
	scanf("%s",shop);
	for(i=0;i<n;i++) scanf("%s",billboard[i]);
	for(i=0;i<n;i++){
		a=0;
		for(j=0;j<strlen(billboard[i]);j++){ 
			if(shop[0]==billboard[i][j]){
				a=max(a,search(j,i,1,0));
			}
		}
		if(a==1) b++;
	}
	printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 1048
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<vector<int> > a(n);
    int i,j;
    for(i=0; i<n; i++) {
        for(j=0; j<n-1; j++) {
            int tmp;
            scanf("%d", &tmp);
            a[i].push_back(tmp-1);
        }
    }

    vector<int> curr(n);
    set<int> check;
    for(i=0; i<n; i++) {
        check.insert(i);
    }

    int ans=0;
    while(1) {
        set<pair<int,int> > z;
        set<int> check_next;

        auto it=check.begin();
        for(; it!=check.end(); ++it) {
            int tmp0=(*it);
            if(curr[tmp0]<n-1) {
                int tmp=a[tmp0][curr[tmp0]];
                if(curr[tmp]<n-1) {
                    if(a[tmp][curr[tmp]]==tmp0) {
                        if(z.insert(make_pair(MIN(tmp0,tmp),MAX(tmp0,tmp))).second) {
                            check_next.insert(tmp0);
                            check_next.insert(tmp);
                        }
                    }
                }
            }
        }

        if(z.empty()) {
            break;
        }
        ans++;
        check.swap(check_next);
        it=check.begin();
        for(; it!=check.end(); ++it) {
            curr[*it]++;
        }
    }

    for(i=0; i<n; i++) {
        if(curr[i]!=n-1) {
            printf("-1\n"); return 0;
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 4352
N, MOD = int(input()), 10 ** 9 + 7
memo = [{} for _ in range(N+1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for x in 'ATGC':
        if ok(last3 + x):
            ret = (ret + dfs(cur + 1, last3[1:] + x)) % MOD
    memo[cur][last3] = ret
    return ret

print(dfs(0, 'TTT'))


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, c, d[30][30], s[500][500], x[3][30];

int main() {
	cin >> n >> c;
	inc(i, c) {
	inc(j, c) {
		cin >> d[i][j];
	}
	}
	inc(i, n) {
	inc(j, n) {
		cin >> s[i][j];
		s[i][j]--;
	}
	}
	
	inc(i, n) {
	inc(j, n) {
		x[(i + j) % 3][s[i][j]]++;
	}
	}
	
	int ans = n * n * 1000 + 1, v = 0;
	inc(i, c) {
	inc(j, c) {
	inc(k, c) {
		if(i == j || j == k || k == i) { continue; }
		v = 0;
		inc(l, c) { v += x[0][l] * d[l][i]; }
		inc(l, c) { v += x[1][l] * d[l][j]; }
		inc(l, c) { v += x[2][l] * d[l][k]; }
		setmin(ans, v);
	}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[90];
main()
{
    int n;scanf("%d",&n);
    a[0]=2;a[1]=1;
    for(int i=2;i<=86;i++)a[i]=a[i-1]+a[i-2];
    printf("%lld\n",a[n]);
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <unordered_map>
#include <queue>
#include <array>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
//const int mod = ;

vl f(vl a, int t) {
  if (t) reverse(a.begin(), a.end());
  int n = a.size();
  vl s(n + 1), v(n);
  for (int i = 0; i < n; ++i) {
    s[i + 1] = s[i] + a[i];
  }
  for (int i = 1; i < n; ++i) {
    ll add = a[i-1] % 2 + 2 * (int)(a[i-1] == 0);
    v[i] = min(s[i], v[i-1] + add);
  }
  if (t) reverse(v.begin(), v.end());
  return v;
}

int main() {
  //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vl a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  if (n <= 1) {
    cout << 0 << endl;
    return 0;
  }
  vl l = f(a, 0), r = f(a, 1);
  ll res = 1e18;
  for (int i = 0; i + 1 < n; ++i) {
    res = min(res, r[i] + l[i+1]);
  }
  vl seven(n + 1);
  for (int i = 0; i < n; ++i) {
    seven[i+1] = seven[i] + 1 - a[i] % 2;
  }
  ll mi = 0;
  for (int i = 0; i < n; ++i) {
    mi = min(mi, l[i] - seven[i]);
    res = min(res, mi + r[i] + seven[i + 1]);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 8136
#include <stdio.h>

void White (int W){
	int j;
	for(j=0; j<W; j++){
		if(j % 2 == 0) putchar('#');
		if(j % 2 == 1) putchar('.');
	}
}

void Black (int W){
	int j;
	for(j=0; j<W; j++){
		if(j % 2 == 0) putchar('.');
		if(j % 2 == 1) putchar('#');
	}
}

void printing (int i, int W){
	if(i % 2 == 0){
		White(W);
		putchar('\n');
	}
	if(i % 2 == 1){
		Black(W);
		putchar('\n');
	}
}
	
void chess (int H, int W){
	int i;
	for(i=0; i<H; i++){
		//H????????§?????????????????????
		printing(i,W);
	}
}

int main(void){
	int H,W;
	scanf("%d %d", &H, &W);
	
	while(H > 0 || W > 0){
		chess(H,W);
		printf("\n");
		scanf("%d %d", &H, &W);
	}
	return 0;
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,col,ans=1e9;
    cin>>n>>col;
    int d[30][30], c[500][500];
    int ls[3][30];// n%3, col
    
    for(int y = 0; y < col; y++)
    {
        for(int x = 0; x < col; x++)
        {
            cin >> d[y][x];
        }    
    }
    
    for(int y = 0; y < n; y++)
    {
        for(int x = 0; x < n; x++)
        {
            cin >> c[y][x];
            c[y][x]--;
            ls[(y+x)%3][c[y][x]]++;
        }        
    }
    
    for(int i = 0; i < col; i++)
    {
        
        for(int j = 0; j < col; j++)
        {
            
            for(int k = 0; k < col; k++)
            {
                if(i==j||j==k||k==i) continue;

                int tmp=0;
                
                for(int ci = 0; ci < col; ci++)
                {
                    tmp+=ls[0][ci] * d[ci][i];
                    tmp+=ls[1][ci] * d[ci][j];
                    tmp+=ls[2][ci] * d[ci][k];
                }
                
                ans=min(ans,tmp);
            }
            
        }
        
    }
    
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main() {
	int a, b, c, kari;
	cin >> a >> b >> c;
	if (a > b) {
		kari = a;
		a = b;
		b = kari;
	}
	if (b > c) {
		kari = b;
		b = c;
		c = kari;
	}
	if (a > b) {
		kari = a;
		a = b; 
		b = kari;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 1164
n = int(input())
A = list(map(int,input().split()))
dp = [[0 for i in range(2)] for _ in  range(n+1)]
dp[0][0] = 0
dp[0][1] = -float('inf')
for i in range(n):
    dp[i+1][0] = max(dp[i][0]+A[i],dp[i][1]-A[i])
    dp[i+1][1] = max(dp[i][0]-A[i],dp[i][1]+A[i])
print(dp[n][0])

Measured memory_bytes: 27084
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint dp[2500][7501];

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

    vector<tuple<lint, lint, lint>> edge; // (from, to, cost)
    for(lint i=0; i<m; i++) {
        lint a, b, c;
        cin >> a >> b >> c;
        edge.emplace_back(--a, --b, p-c);
    }

    fill(dp[0], dp[2500], LLONG_MAX);
    dp[0][0] = 0;
    for(lint len=1; len<=7500; len++)
    for(auto& e : edge) {
        lint from, to, cost;
        tie(from, to, cost) = e;
        if(dp[from][len-1] == LLONG_MAX)  continue;
        dp[to][len] = min(dp[to][len], dp[from][len-1] + cost);
    }

    auto x = dp[n-1];
    auto it = min_element(x + 2500, x + 7501);
    if(it - x >= 5000)  cout << -1 << endl;
    else  cout << max(0LL, -*min_element(x, x+2500)) << endl;
}

Measured memory_bytes: 147008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000005],f[1000005];
ll s[1000005];
int n;
bool check(ll x,ll k){
	for(int i=0;i<n;i++){
		if(1ll*a[i]*f[n-1-i]<=x)
			continue;
		ll num=1ll*x/f[n-1-i];
		if(a[i]>num)
			k=k-a[i]+num;
		//if(x==7)
		//	cout<<'\t'<<a[i]-num<<'\t'<<k<<endl;
		if(k<0)
			return false;
	}
	return true;
} 
int main(){
	ll k;
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",a+i);
	for(int i=0;i<n;i++)
		scanf("%d",f+i);
	sort(a,a+n);
	sort(f,f+n);
	//for(int i=0;i<n;i++)
	//	cout<<a[i]<<" "<<f[n-1-i]<<endl;
	ll L=0,R=1e12+5,mid;
	
	//cout<<endl<<check(7,k)<<endl;
	
	while(L<R){
		mid=(L+R)/2;
		if(check(mid,k))
			R=mid;
		else
			L=mid+1;
		//cout<<L<<" "<<R<<endl;
	}
	printf("%lld",R);
}

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

int main(){

    while(1){
        int n; cin >> n;
        if(!n) break;

        string a[1002];
        int b[1002];
        for(int i = 0; i < n; i++){
            cin >> a[i];
            if(a[i][0] != 'x') b[i] = stoi(a[i]);
        }

        int u = 1000000002;
        int d = -1000000002;

        bool flag = true;
        
        //ｘ二個並んでないかのチェック
        for(int i = 0; i < n - 1; i++){
            if(a[i][0] == 'x' && a[i + 1][0] == 'x'){
                flag = false;
                break;
            }
        }

        if(!flag){
            cout << "none" << endl;
            continue;
        }

        for(int i = 0; i < n; i++){
            if(i == 0){
                if(a[0][0] == 'x') u = b[1] - 1;
                else{
                    if(a[1][0] != 'x'){
                        if(b[1] < b[0]){
                            //cout << a[1] << endl;
                            flag = false;
                            break;
                        }
                    }
                }
            }else if(i == n - 1){
                if(a[i][0] == 'x'){
                    if(i % 2 == 0){
                        u = min(u + 1, b[i - 1]) - 1;
                    }else{
                        //cout << 3 << endl;
                        d = max(d - 1, b[i - 1]) + 1;
                    }
                }else{
                    if(a[i - 1][0] == 'x'){}
                    else if(i % 2 == 0 && b[i] > b[i - 1]){
                        flag = false;
                        break;
                    }else if(i % 2 == 1 && b[i] < b[i - 1]){
                        flag = false;
                        break;
                    }
                }
            }else{

                if(a[i][0] == 'x'){

                    if(i % 2 == 0) u = min(u + 1, min(b[i - 1], b[i + 1])) - 1;
                    else d = max(d - 1, max(b[i - 1], b[i + 1])) + 1;
                }else{

                    if(i % 2 == 0){
                        if(a[i - 1][0] != 'x' && b[i - 1] < b[i]){
                            flag = false;
                            break;
                        }
                        if(a[i + 1][0] != 'x' && b[i + 1] < b[i]){
                            flag = false;
                            break;
                        }
                    }
                }
            }
        }

        //cout << u << " " << d << endl;
        if(!flag || u < d) cout << "none" << endl;
        else if(u == d) cout << u << endl;
        else cout << "ambiguous" << endl;
    }

    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	string S;
	cin >> S;
	bool flag = false;
	fx(S.size()-1) {
		if (S.at(x) == S.at(x + 1)) {
			flag = true;
			break;
		}
	}
	if(flag)
		ce("Bad")
	else
		ce("Good")
    return 0;
}



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

int main() {
    string s, t;
    cin >> s >> t;
    int count = 0;

    rep(i, s.length()){
        if(s[i] != t[i]){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3916
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define Maxn 200005
#define LL long long
#define R register

int n,a[Maxn];
LL ans;

int main()
{
	scanf("%d",&n);
	for (R int i=1;i<=n;++i)scanf("%d",&a[i]),a[n+i]=a[i];
	sort(a+1,a+n*2+1); 
//	for (R int i=1;i<=2*n;++i)printf("%d ",a[i]);puts("");
	if(n == 2)
	{
		printf("%d\n",abs(a[3]-a[2]));
		return 0;
	}
	if(n&1)
	{
		for(R int i=2*n;i>=n+4;--i) ans += a[i];
		for(R int i=1;i<=n-3;++i) ans -= a[i];
		ans+=a[n+3]-a[n-2];
		ans=max(ans+a[n+2]-a[n+1],ans+a[n]-a[n-1]);
	}
	else
	{
		for(R int i=2*n;i>=n+3;--i) ans += a[i];
		for(R int i=1;i<=n-2;++i) ans -= a[i];
		ans+=a[n+2]-a[n-1];
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(n%2!=0){
		cout<<"No"<<endl;
		return 0;
	}	
	for(int i=0;i<=n/2-1;i++){
		if(s[i]!=s[i+n/2]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>
int fw(const void *a, const void *b)
{
    return *(long int *)a - *(long int *)b;
}
int bw(const void *a, const void *b)
{
    return *(long int *)b - *(long int *)a;
}
int main()
{
    char s[5];
    int ans = 0;
    scanf("%s", s);

    for (int i = 0; i < 4; i++)
    {
        if (s[i] == '2')
            ans++;
    }
    printf("%d", ans);
    return 0;
}

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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> m(n);
	for (int i = 0; i < n; i++) cin >> m.at(i);

	sort(m.begin(), m.end());
	cout << n + (x - accumulate(m.begin(), m.end(), 0)) / m.front();

 	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    S=set(list(input()))
    T=[]
    for i in range(26):
        T.append(chr(i+97))
    T=set(T)
    ans=list(T-S)

    if ans==[]:
        print("None")
    else:
        ans.sort()
        print(ans[0])
    
    
    

main()


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

int main() {
  int N;
  cin>>N;
  int A[N];
  for (int i=0; i<N; i++) {
    cin>>A[i];
  }
  int sw=0;
  for (int i=0; i<N; i++) {
    int minj=i;
    for (int j=i; j<N; j++) {
      if (A[j]<A[minj]) {
        minj=j;
      }
    }
    swap(A[i],A[minj]);
    if (i!=minj) {
      sw++;
    }
  }
  for (int i=0; i<N; i++) {
    cout<<(i==0?"":" ")<<A[i]<<flush;
  }
  cout<<endl;
  cout<<sw<<endl;
  return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int N;
const double EPS=1e-8;
int p[15],d[15],c[15];
double dp[1<<16][15];

int w[1<<16];
int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++)scanf("%d%d%d",&p[i],&d[i],&c[i]);

    fill_n(*dp,(1<<16)*15,1e9);
    for(int i=0;i<N;i++){
        dp[(1<<i)][i]=0;
    }

    w[0]=0;

    for(int i=0;i<(1<<16);i++){
        for(int j=0;j<N;j++){
            if((i>>j)&1)continue;
            w[i|(1<<j)]=w[i]+c[j];
        }
    }

    for(int i=1;i<(1<<16);i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++){
                if((i>>k)&1)continue;
                double t=fabs(d[j]-d[k])/(2000/(70+w[i]*20.0));
                dp[i|(1<<k)][k]=min(dp[i|(1<<k)][k],dp[i][j]+t);
            }
        }
    }

    int s=(1<<N)-1;
    int pos=0;
    for(int i=1;i<N;i++){
        if(dp[s][pos]>dp[s][i])pos=i;
    }
    vector<int>ans(1,pos);

    for(int i=0;i<N-1;i++){
        for(int j=0;j<N;j++){
            if(((s>>j)&1)==0)continue;
            if(fabs(dp[s^(1<<pos)][j]+fabs(d[j]-d[pos])/(2000/(70+w[s^(1<<pos)]*20.0))-dp[s][pos])<EPS){
                ans.push_back(j);
                s=s^(1<<pos);
                pos=j;
                break;
            }

        }
    }

    reverse(ans.begin(),ans.end());
    for(int i=0;i<ans.size();i++){
        if(i)printf(" ");
        printf("%d",p[ans[i]]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll dp[110][100010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,W;
    ll w[110], v[110];
    cin >> N >> W;
    rep(i,0,N){
        cin >> w[i] >> v[i];
    }
    rep(i,0,N){
        rep(j,0,W+1){
            if(j - w[i] >= 0){
                dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    print(dp[N][W]);
}


Measured memory_bytes: 79360
// https://atcoder.jp/contests/arc067/tasks/arc067_b
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];
    ll sum = 0;
    REP(i, n - 1) sum += min((v[i + 1] - v[i]) * a, b);
    cout << sum << endl;

    return 0;
}


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

int main(){
    int n;
    string s;
    cin>>n>>s;   
    int cnt=0;

    for (int i=0;i<n-2;i++){
        if(s.substr(i,3)=="ABC"){
            cnt++;
        }
    }
    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 3600
using System;
using System.Linq;
class Program {
    static void Main(string[] args) {
        var s = Console.ReadLine().Split(' ').Select(p => long.Parse(p)).ToArray();
        long x = s[0];
        long y = s[1];
        long mod = 1000000007;

        if ((x + y) % 3 != 0) {
            Console.WriteLine("0");
            return;
        }

        long a = (2 * x - y) / 3;
        long b = (2 * y - x) / 3;

        //片方でも負の数があれば、答えはゼロとなる
        if (a < 0 || b < 0) {
            Console.WriteLine("0");
            return;
        }

        //まずは分子のmodを計算する
        long ans = FactorialMod(a + b, mod);

        //分母の逆元modをかける
        ans = ans * FactoricalModInv(a, mod) % mod * FactoricalModInv(b, mod) % mod;

        Console.WriteLine(ans);
    }

    //mod付き階乗の計算
    static long FactorialMod(long n, long m) {
        if (n <= 1) {
            return 1;
        }
        return n * FactorialMod(n - 1, m) % m;
    }

    //aの逆元を求める
    static long ModInv(long a, long M) {
        if (a <= 1) {
            return 1;
        }
        long m = (-(ModInv(M % a, M) * (M / a))) % M;
        if (m < 0) {
            m += M;
        }
        return m;
    }

    //分母の階乗をしながら逆元を求めていく
    static long FactoricalModInv(long a, long M) {
        if (a <= 1) {
            return 1;
        }
        return FactoricalModInv(a - 1, M) * ModInv(a, M) % M;
    }
}

Measured memory_bytes: 34132
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


def merge(a, b):
    res = []
    i, j = 0, 0
    while i < len(a) or j < len(b):
        if j >= len(b) or (i < len(a) and a[i][0] < b[j][0]):
            w, v = a[i]
            i += 1
        else:
            w, v = b[j]
            j += 1
        if not res or res[-1][1] < v:
            res.append((w, v))
        elif res[-1][0] == w and res[-1][1] <= v:
            res.pop()
            res.append((w, v))
    return res


def best(L, a, b):
    res = 0
    i = 0
    j = len(b) - 1
    while i < len(a):
        w, v = a[i]
        if j < 0:
            break
        if b[j][0] + w > L:
            j -= 1
            continue
        res = max(res, v + b[j][1])
        i += 1
    return res


def main():
    N = int(input())
    VW = [(-1, -1)] + [list(map(int, input().split())) for _ in range(N)]
    Q = int(input())
    query = tuple(tuple(map(int, input().split())) for _ in range(Q))

    dp = [[] for _ in range(2048)]
    dp[0] = [(0, 0)]
    for i in range(1, min(N + 1, 2048)):
        vi, wi = VW[i]
        a1 = dp[i // 2]
        a2 = [(w + wi, v + vi) for w, v in a1]
        dp[i] = merge(a1, a2)

    for n, L in query:
        a = [(0, 0)]
        while n >= 2048:
            vi, wi = VW[n]
            b = [(w + wi, v + vi) for w, v in a]
            a = merge(a, b)
            n //= 2
        print(best(L, a, dp[n]))


if __name__ == "__main__":
    main()

Measured memory_bytes: 198704
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val k = sc.nextInt()
    abc161d(k)
}

fun abc161d(k:Int) {
    var count = 0
    val que: LinkedList<Long> = LinkedList<Long>((1L..9L).toList())
    if(k <= 9) return println(que[k-1])
    while (count < k){
        count++
        if(count == k){
            println(que.poll())
            break
        }
        val tmp = que.poll()
        val suf = tmp%10L
        if(suf != 0L) que.add(tmp*10L+(suf-1L))
        que.add(tmp*10L+suf)
        if(suf != 9L) que.add(tmp*10L + (suf+1L))
    }

}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }



Measured memory_bytes: 51208
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a2,a4,a6,b2,b4,b6,c,q,i,j,z=0,k=1,o=0,m[1001][1001]={0};
  int a[1001]={0},b[1001]={0},w[1001]={0},e[6][2]={0};
  for(a2=a4=a6=b2=b4=b6=i=0;i<6;i++){
    cin>>q>>c;
    w[q]++;
    w[c]++;
    if(q>c)m[q][c]++;
    else m[c][q]++;
  }
  for(i=0;i<1001;i++){
    if(w[i])o++;
      for(j=0;j<1001;j++){
        if(m[i][j]){a[j]+=m[i][j];b[i]+=m[i][j];
	  if(m[i][j]==4){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
	  else if(m[i][j]==6){e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;e[z][0]=i;e[z++][1]=j;}
	  else{ e[z][0]=i;e[z++][1]=j;}
	}
       }
    }
  if(e[0][0]!=e[2][1]||e[1][0]!=e[2][0]||e[0][1]!=e[1][1]||o>3)k=0;
  if(k)cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, K;
    cin >> n >> K;
    vector<int> p(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> p[i + 1];
        p[i + 1] += p[i] + 1;
    }

    int ans = 0;
    for (int i = K; i <= n; ++i) {
        ans = max(ans, p[i] - p[i - K]);
    }
    cout << fixed << setprecision(15) << ans / 2.0 << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int x,y;
    while(1){
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x <= y){
            cout << x << " " << y << endl;
        }else if(x > y){
            cout << y << " " << x << endl;
        }
    }
    return 0;
}


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

int main(void)
{
    int N, M;
    cin >> N >> M;
    bool tkhsScore[N];
    for (int i = 0; i < N; i++) {
        tkhsScore[i] = false;
    }
    int WA[N];
    for (int i = 0; i < N; i++) {
        WA[i] = 0;
    }


    for (int i = 0; i < M; i++) {
        int p;  string S;
        cin >> p >> S;
        // AC
        if(S[0] == 'A') {
            tkhsScore[p-1] = true;
        }
        // WA
        else {
            if (tkhsScore[p-1] == false) {
                WA[p-1]++;
            }
        }
    }
    int ansNum = 0;
    int penNum = 0;
    for (int i = 0; i < N; i++) {
        if (tkhsScore[i] == true) {
            ansNum++;
            penNum += WA[i];
        }
    }
    cout << ansNum << " " << penNum << endl;

}

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

using LL = long long int;
constexpr LL MOD = 1e9 + 7;
pair<int, int> directions[] = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };

class Solution {
public:

};

void test() {
    Solution s;
}

void run() {
    Solution s;
}

int main() {
//    test();
//    run();
    string s;
    while (cin >> s) {
        int insert = 0;
        bool valid = true;
        for(int i = 0, j = s.length() - 1; i < j; ) {
            if(s[i] == s[j]) {
                ++ i;
                -- j;
            }
            else if(s[i] == 'x') {
                ++ insert;
                ++ i;
            }
            else if(s[j] == 'x') {
                ++ insert;
                -- j;
            }
            else {
                valid = false;
                break;
            }
        }
        cout << (valid ? insert : -1) << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <algorithm>

using namespace std; 

long long n, ans = 1e18; 
long long a, b, c, d; 
map <long long, long long> dp;

long long dfs(long long n) {
    if (dp[n]) return dp[n]; 
    if (n == 0) return 0; 
    dp[n] = 1e18;  
    if (n < dp[n] / d) 
        dp[n] = min(dp[n], n * d);
    if (n % 2 == 0) {
        dp[n] = min(dp[n], dfs(n / 2) + a); 
    }
    else {
        dp[n] = min(dp[n], dfs((n + 1) / 2) + a + d); 
        dp[n] = min(dp[n], dfs((n - 1) / 2) + a + d); 
    }
    if (n % 3 == 0) {
        dp[n] = min(dp[n], dfs(n / 3) + b); 
    }
    else {
        dp[n] = min(dp[n], dfs(n / 3) + b + d * (n % 3)); 
        dp[n] = min(dp[n], dfs(n / 3 + 1) + b + d * (3 - n % 3)); 
    }
    if (n % 5 == 0) {
        dp[n] = min(dp[n], dfs(n / 5) + c); 
    }
    else {
        dp[n] = min(dp[n], dfs(n / 5) + c + d * (n % 5)); 
        dp[n] = min(dp[n], dfs(n / 5 + 1) + c + d * (5 - n % 5)); 
    }
    return dp[n]; 
}
int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        ans = 9e18; 
        dp.clear(); 
        cin >> n >> a >> b >> c >> d; 
        printf("%lld\n", dfs(n)); 
    }
    return 0; 
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, k, r, s, p;

int main() {
	cin.sync_with_stdio(false); cin.tie(0);
	cin.exceptions(cin.failbit);

	cin >> n >> k >> r >> s >> p;
	string t; cin >> t;
	int a = 0;
	
	rep(i, 0, k) {
		int sr = 0, ss = 0, sp = 0;
		for (int j = i; j < n; j += k) {
			int sr2 = max(ss, sp) + r * int(t[j] == 's');
			int ss2 = max(sr, sp) + s * int(t[j] == 'p');
			int sp2 = max(ss, sr) + p * int(t[j] == 'r');
			sr = sr2, ss = ss2, sp = sp2;
		}
		a += max({sr, ss, sp});
	}
	cout << a << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<memory>
#include <vector>
#include <string>
#include<sstream>

using namespace std;

void trace(vector<int> &vec){
    int i;
    for (i = 0; i < vec.size(); i++){
        if (i > 0 ) cout << " ";
        cout << vec[i];
    }
    cout << '\n';
}

void InsertionSort(vector<int> &vec)
{
    int j, i, v;
    for (i = 1; i < vec.size(); i++){
        v = vec[i];
        j = i-1;
        while( j >= 0 && vec[j] > v){
            vec[j + 1] = vec[j];
            j--;
        }
        vec[j + 1] = v;
        trace(vec);
    }
}
 
int main(){
    int N, i, j;
    cin >> N;
    vector<int> vec(N);
    int val;
    for(i = 0; i < N; i++){
        cin >> val;
        vec[i] = val;
    }

    trace(vec);
    InsertionSort(vec);
}


Measured memory_bytes: 3104