akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x,y) __gcd(x,y)
#define PI 3.14159265
#define endl "\n"
#define count_ones __builtin_popcountl
#define piii pair<int,pair<int,int>>
const int N=1e5+20,MOD=(int)(1e9)+7;
const int oo = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
void boost(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}
/* -------------------------------------- */
bool compare(pair<int,int>a , pair<int,int> b){
	return (a.first > b.first);
}
int main() {
	boost();
	ll n,m;cin>>n>>m;
	map<int,vector<int>> mp;int a,b;
	for(int i=0;i<n;i++){cin>>a>>b;
		mp[a].push_back(b);
	}
	ll ans=0;
	priority_queue<int> pq;
	for(int i=1;i<m+1;i++){
		for(auto ele : mp[i]){
			pq.push(ele);
		}
		if(!pq.empty()){
			ans += pq.top();pq.pop();
		}
	}
	cout<<ans;
}

Measured memory_bytes: 10880
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;
int main(){

  int x=0;
  int N;
  string S;
  cin>>N>>S;
  int M =0;
  rep(i,0,N){
    if(S[i]=='I'){
      x++;
    }else{
      x--;
    }
  
    if(M<x){
      M=x;
    }
  }
  cout<<M;
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


Measured memory_bytes: 256
N,K=map(int,input().split())
a=0
b=0
count=0
if K==0: 
    print(N*N)
else:
    for i in range(1,N+1):
        a=N//i
        b=N%i
        if i>=K:
            count+=(i-K)*a
            if b>=K:
                count+=b-K+1
    print(count)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){

	double a,b,c,d,e,f;
	double x,y;
	
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
	
	
		if((x = (1/(a*e-d*b))*(e*c+-b*f)) == -0.000000)
			x = 0.000000;
		if((y = (1/(a*e-d*b))*(-d*c+a*f)) == -0.000000)
			y = 0.000000;
		
		printf("%.3lf %.3lf\n",x,y); 
	
	}

	return 0;
}

Measured memory_bytes: 652
using System;
using System.Linq;

class Program
{
    static void Main()
    {
    
        var line = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var n = line[0];
        var m = line[1];
        var l = line[2];

        int [,]atable = new int[n, m];
        int [,]btable = new int[m, l];
        long [,]ctable = new long[n, l];
        
        for(int i = 0; i < n; i++){
            var tline = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            for(int tl = 0; tl < m; tl++){
                atable[i, tl] = tline[tl];
            }
        }
        
        for(int i = 0; i < m; i++){
            var tline = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            for(int tl = 0; tl < l; tl++){
                btable[i, tl] = tline[tl];
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int tl = 0; tl < l; tl++){
                for(int ml = 0; ml < m; ml++){
                    ctable[i, tl] += atable[i, ml]*btable[ml, tl];
                }
            }
        }
        
        for(int i = 0; i < n; i++){
            for(int tl = 0; tl < l; tl++){
                Console.Write(ctable[i, tl]);
                
                if(tl != l-1){
                    Console.Write(" ");
                }
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 18412
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

int main(int argc, char const* argv[])
{
    string S;
    cin >> S;
    rep(i,S.length()){
        if( i%2 == 0 ){
            if(S[i] == 'L' ){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(S[i] == 'R' ){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

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

  // dp[i] = (i番目までで条件を満たす最も少ない分割数)
  // dp[i] = dp[j] + 1 (a[i]^a[j]が0もしくは2べき)
  // dp2[i] = (ハッシュ値がiのもののうち分割数のmin)
  // dp[i] = min(dp[a[i]^x]) + 1

  ll a = 0;
  vector<int> dp(n), dp2(1LL<<26, INF);
  dp[0] = 0, dp2[0] = 0;
  REP(i, n) {
    a ^= 1LL<<(s[i]-'a');
    int mi = dp2[a];
    REP(j, 26) chmin(mi, dp2[a^(1LL<<j)]);
    dp[i] = mi + 1;
    chmin(dp2[a], dp[i]);
  }
  cout << dp[n-1] << endl;

  return 0;
}


Measured memory_bytes: 263572
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

def getPath():
    curr = 1
    path = [curr]
    seen = {curr}
    while A[curr - 1] not in seen:
        curr = A[curr - 1]
        path.append(curr)
        seen.add(curr)
    assert A[curr - 1] in seen
    index = path.index(A[curr - 1])
    return path[:index], path[index:]

path, cycle = getPath()
if K + 1 < len(path) + len(cycle):
    print((path + cycle)[K])
else:
    print(cycle[(K - len(path)) % len(cycle)])

Measured memory_bytes: 129504
H, W, K = map(int, input().split())
c = []
for i in range(H):
    new = input()
    c.append(new)

ans = 0
for i in range(2**H):
    i_format = "0"+str(H)+"b"
    i_bin = format(i, i_format)
    for j in range(2**W):
        j_format = "0"+str(W)+"b"
        j_bin = format(j, j_format)
        count = 0
        for n in range(H):
            row = c[n]
            if i_bin[n] == "0":
                for m in range(W):
                    if j_bin[m] == "0":
                        if row[m] == "#":
                            count += 1      
        if count == K:
            ans += 1
print(ans)
            
        

Measured memory_bytes: 9144
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;




int main(void) {
	int si,a,z;
	z=0;
	a=0;
	string s;
	cin >> s;
	si = s.length();
	for (int i = 0; i < si; i++) {
		if (s[i] == 'A'){
		    a = i;
		    break;
		}
	}
	for (int i = si - 1; i > 0; i--) {
		if (s[i] == 'Z'){
		    z = i;
		    break;
		}
	}
	
	cout << (z - a) + 1 << endl;
}

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

#define ucin ios::sync_with_stdio(0), cin.tie(0)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
typedef pair<int, int> pii;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;

const int N = 110 + 10;
const int mod = 1e9 + 7;

int qpow(int a, int b) {
	int ans = 1;
	for(; b >= 1; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) ans = (ll) ans * a % mod;
	return ans;
}
int n, m, dp[N][N];
char s[N][N];
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i ++)
		scanf("%s", s[i] + 1);
	for(int i = 1; i <= n; i ++) {
		for(int j = 1; j <= m; j ++) {
			if(i == 1 && j == 1) {
				dp[1][1] = s[1][1] == '#';
			} else if(i == 1) dp[1][j] = dp[1][j - 1] + (s[1][j] == '#' && s[1][j - 1] != '#');
			else if(j == 1) dp[i][1] = dp[i - 1][1] + (s[i][1] == '#' && s[i - 1][1] != '#');
			else {
				dp[i][j] = min(dp[i - 1][j] + (s[i][j] == '#' && s[i - 1][j] != '#'), dp[i][j - 1] + (s[i][j] == '#' && s[i][j - 1] != '#'));
			}
		}
	}
	printf("%d\n", dp[n][m]);
	return 0;
}

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

int main()
{
  int n, ans = 0, max = 0;
  cin >> n;
  for(int i=0; i<n; i++)
  {
    int h;
    cin >> h;
    if(h >= max)
    {
      ans++;
      max = h;
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const long long inf2=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define SZ 100005
int n;
struct thing{
	int a,b;
	int dif;
	void input(){
		scanf("%lld%lld",&a,&b);
		dif=a+b;
	}
};
bool operator<(thing a,thing b){
	return a.dif!=b.dif?a.dif>b.dif:a.a>b.a;
}
multiset<thing>th;
signed main(){
	scanf("%lld",&n);
	for(int i=0;i<n;i++){
		thing t;
		t.input();
		th.insert(t);
	}
	cerr<<"ok init\n";
	int ans=0;
	for(int i=0;i<n;i++){
		if(i&1){
			ans-=(*th.begin()).b;
		}else{
			ans+=(*th.begin()).a;
		}
		th.erase(th.begin());
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = list(map(int, input().split()))
    C = [0 for _ in range(N)]

    for i in range(N):
        C[A[i] - 1] = i + 1

    print(' '.join(map(str, C)))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 18368
import java.util.Scanner;

public class Main {
	static final int N = 1000;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int q = scan.nextInt();
		for(int i = 0; i < q; i++) {
			String s1 = scan.next();
			String s2 = scan.next();
			System.out.println(lcs(s1, s2));
		}
		scan.close();

	}
	static int lcs(String X, String Y) {
		int[][]c = new int[N + 1][N + 1];
		int m = X.length();
		int n = Y.length();
		int maxl = 0;
		X = " " + X;
		Y = " " + Y;
		for(int i = 1; i <= m; i++) {
			for(int j = 1; j <= n; j++) {
				if(X.charAt(i) == Y.charAt(j)) {
					c[i][j] = c[i - 1][j - 1] + 1;
				}else {
					c[i][j] = Math.max(c[i - 1][j], c[i][j - 1]);
				}
				maxl = Math.max(maxl, c[i][j]);
			}
		}
		return maxl;
	}
}


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

#define MOD_N    1000000007
typedef long long ll;

int N, M;
vector<int> X, Y;


int main(void) {
	ll xx, yy, ans;

	cin >> N >> M;
	X.resize(N);
	Y.resize(M);
	for (int i = 0; i < N; ++i)
		cin >> X[i];
	for (int j = 0; j < M; ++j)
		cin >> Y[j];
	xx = 0;
	for (int k = 0; k < N; ++k) {
		xx += (ll)k * X[k] - (ll)(N - k - 1) * X[k];
		xx %= MOD_N;
	}
	yy = 0;
	for (int k = 0; k < M; ++k) {
		yy += (ll)k * Y[k] - (ll)(M - k - 1) * Y[k];
		yy %= MOD_N;
	}
	ans = (xx * yy) % MOD_N;

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


 
int main() {
    int n, a;
    cin >> n;
    vector<int> var;
    for (int i = 0; i < n;i++){
        cin >> a;
        var.push_back(a);
    }
    sort(var.begin(), var.end());
    cout <<  var.at(n/ 2) - var.at(n / 2 - 1)  << endl;
}

Measured memory_bytes: 892
/*

  _    _ _      _ _      _ _     _____ ____________ 
 | |__| | | _ _| | | _ _| | | __|__ / |__ /__ /__  |
 | '_ \_  _| ' \_  _| ' \_  _(_-<|_ \ ||_ \|_ \ / / 
 |_.__/ |_||_||_||_||_||_||_|/__/___/_|___/___//_/  

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << '\n'
#define rep(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(x) scanf("%s", x)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(x) printf("%s\n", x)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define F first
#define S second
#define pb push_back
#define ll long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int mpow(int base, int exp);
void ipgraph(int n,int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1e3+7, M = N, OO = 1e9 + 7;
const ll LLOO = 1e18 + 7;
//=======================

vi g[N];
char buff[N];

void solve()
{
    ss(buff);
    string a = (string)buff;
    ss(buff);
    string b = (string)buff;
    
    int n = a.size();
    int m = b.size();
    int ans = OO;
    rep(i,0,n)
    {
		int res = 0;
		int k = 0;
		rep(j,i,n)
		{
			if (k > m-1) {break;} 
			res += (a[j] != b[k]);
			k++;
		}
		if (k == m) ans = min(ans,res);
	}
	pi(ans);
}

int main()
{
    // uncomment if file :
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);
    int t = 1;
    // si(t); // uncomment if testcases
    while (t--)
        solve();
    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int u, v;
    while (m--)
    {
        scanf("%d %d", &u, &v);
        g[u - 1].pb(v - 1);
        g[v - 1].pb(u - 1);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (v == par)
            continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 3816
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
#define int long long int
#define mod 1000000007
int function2(int n,int memo[][2][2],int status1,int status2)
{
	if(n==0)
	{
		if(status1&&status2)
		   return 1;
		else
		  return 0;
	}
	if(memo[n][status1][status2]!=-1)
	  return memo[n][status1][status2];
	else
	{
		int answer=0;
		answer+=function2(n-1,memo,status1|1,status2);
		answer+=function2(n-1,memo,status1,status2|1);
		answer+=8*function2(n-1,memo,status1,status2);
		answer%=mod;
		memo[n][status1][status2]=answer;
		return answer;
	}
}
int32_t main()
{
	//function2();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int memo[n+1][2][2];
	int i,j,k;
	for(i=0;i<=n;i++)
	{
		for(j=0;j<2;j++)
		{
			for(k=0;k<2;k++)
			{
				memo[i][j][k]=-1;
			}
		}
	}
	int answer=function2(n,memo,0,0);
	cout<<answer<<endl;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;
const int MAX_V=210;

int V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v){
	G[u].push_back(v);
	G[v].push_back(u);
}
bool dfs(int v){
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		int u=G[v][i], w=match[u];
		if(w<0 || !used[w] && dfs(w)){
			match[v]=u;
			match[u]=v;
			return true;
		}
	}
	return false;
}

int bipartite_matching(){
	int res=0;
	memset(match,-1,sizeof(match));
	for(int v=0;v<V;v++){
		if(match[v]<0){
			memset(used,0,sizeof(used));
			if(dfs(v)){
				res++;
			}
		}
	}
	return res;
}

int main(){
	vector<pii> red,blue;
	cin>>V;
	REP(i,V){
		int a,b;
		cin>>a>>b;
		red.push_back(pii(a,b));
	}
	REP(i,V){
		int c,d;
		cin>>c>>d;
		blue.push_back(pii(c,d));
	}
	for(int i=0;i<V;i++){
		for(int j=0;j<V;j++){
			if(red[i].first<blue[j].first && red[i].second<blue[j].second){
				add_edge(i,V+j);
			}
		}
	}
	cout<<bipartite_matching()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    char name[20];
    int vl;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N;
    scanf("%d",&N);
    int sum=N+N*N+N*N*N;
    printf("%d",sum);
}


Measured memory_bytes: 1732
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<queue>

using namespace std;

int main(){

    int N;
    cin >> N;
    for(int i=0;i<N;i++){
	int G,y,n;
	cin >> G >> y >> n;
	int risi;
	double intere;
	long tes,res=0;
	for(int j=0;j<n;j++){
	    long temp=G,ti = 0;
	    cin >> risi >> intere>> tes;
	    for(int k=0;k<y;k++){
		if(risi){
		    temp *= 1.0 + intere;
		    temp -= tes;
		}else{
		    ti += temp*intere;
		    temp -= tes;
		}
	    }
	    temp += ti;
	    res = max(res,temp);
	}
	cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N;
	static String str;
	static int[][] memo;

	public static void main(String[] a) {
		str = sc.next();
		N = str.length();
		memo = new int[N + 1][N + 1];
		System.out.println(rec(0, N) ? "Cat" : "Rabbit");
	}

	static boolean rec(int s, int e) {
		if (s == e) return true;
		if (memo[s][e] != 0) return memo[s][e] == 1 ? true : false;
		if (str.charAt(s) != 'm') return false;
		if (str.charAt(e - 1) != 'w') return false;
		boolean ret = false;
		for (int i = s + 1; i < e - 1; ++i) {
			if (str.charAt(i) != 'e') continue;
			if (rec(s + 1, i) && rec(i + 1, e - 1)) {
				ret = true;
				break;
			}
		}
		memo[s][e] = ret ? 1 : -1;
		return ret;
	}

}

Measured memory_bytes: 25704
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
struct edge{int to,cost;};
struct state{
  int pos,S;
  double cost;
  bool operator < (const state &p)const{
    return cost > p.cost;
  }
};

int n,m,p,a,b;
double t[8];
vector<edge> G[31];
double d[31][(1<<8)];
void init(){
  for(int i=0;i<31;i++){
    G[i].clear();
    for(int j=0;j<(1<<8);j++)d[i][j]=(1<<26);
  }
}

void solve(){
  d[a][0]=0;
  priority_queue<state> Q;
  Q.push((state){a,0,0});
  while(!Q.empty()){
    state s=Q.top();Q.pop();
    if(s.pos==b){
      printf("%.8f\n",s.cost);
      return;
    }
    if(s.cost>d[s.pos][s.S])continue;
    for(int i=0;i<(int)G[s.pos].size();i++){
      edge e=G[s.pos][i];
      for(int j=0;j<n;j++){
	if((s.S>>j)&1)continue;
	int nS=s.S+(1<<j);
	if(s.cost+e.cost/t[j]<d[e.to][nS]){
	  d[e.to][nS]=s.cost+e.cost/t[j];
	  Q.push((state){e.to,nS,d[e.to][nS]});
	}
      }
    }
  }
  cout<<"Impossible"<<endl;
}

int main(){
  while(1){
    cin>>n>>m>>p>>a>>b;
    if(n+m+p+a+b==0)break;
    init();
    for(int i=0;i<n;i++)cin>>t[i];
    for(int i=0;i<p;i++){
      int x,y,z;
      cin>>x>>y>>z;
      G[x].push_back((edge){y,z});
      G[y].push_back((edge){x,z});
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 2812
#!/usr/bin/env python

n, k = map(int, input().split())
L = [0 for _ in range(k)]
R = [0 for _ in range(k)]
for i in range(k):
    L[i], R[i] = map(int, input().split())
mod = 998244353

dp = [0 for _ in range(n+1)]
dp[1] = 1 
cumsum = [0 for _ in range(n+1)]
cumsum[1] = 1 

# O(NK)
for i in range(2, n+1):
    for j in range(k):
        li = i-R[j]
        ri = i-L[j]
        if ri<0: continue
        li = max(li, 1)
        dp[i] += (cumsum[ri]-cumsum[li-1])%mod
    cumsum[i] = cumsum[i-1]+dp[i]

print(dp[n]%mod)


Measured memory_bytes: 30136
#include<iostream>
#include<string>
#include<sstream>
#include<cstdlib>

using namespace std;

int main(){
	while(1){
		string str;
		getline(cin,str);
		int n = atoi(str.c_str());
		if(n==0)break;
		int scoreA = 0, scoreB = 0;
		while(n--){
			getline(cin,str);
			stringstream ss(str);
			string tmp;
			getline(ss,tmp,' ');
			int a = atoi(tmp.c_str());
			getline(ss,tmp);
			int b = atoi(tmp.c_str());
			if(a>b)scoreA+=(a+b);
			else if(b>a) scoreB+=(a+b);
			else{
				scoreA+=a;
				scoreB+=b;
			}
		}
		cout<<scoreA<<" "<<scoreB<<endl;
	}
	return 0;
}

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

using namespace std;

#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i, n) for(int i = 1; i <= n; ++i)

typedef long long ll;
typedef pair<int, int> pii;

const int N = 200200;
const int mod = 1e9 + 7;
int n, m, u, v, can1[N + N], can2[N + N];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	fo(i, m)
	{
		cin >> u >> v;
		if(u > v) swap(u, v);
		if(u == 1)
			can1[v] = 1;
		if(v == n)
			can2[u] = 1;
	}	
	fo(i, n)
		if(can1[i] && can2[i])
			return cout << "POSSIBLE\n", 0;
	cout << "IMPOSSIBLE";	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define MAX 100000
using namespace std;
using pi = pair<int, int>;

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
	T sub(int l, int r, int node, int lb, int ub) const {
		if (ub <= l || r <= lb) return id;
		if (l <= lb && ub <= r) return data[node];
		return merge(sub(l, r, node * 2, lb, (lb + ub) / 2), sub(l, r, node * 2 + 1, (lb + ub) / 2, ub));
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(size(n_) * 2, id_) {}
	SegmentTree(const vector<T>& data_, T id_, func_t merge_) :
		n(size(data_.size())), id(id_), merge(merge_), data(size(data_.size()) * 2, id_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	void Update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	void Add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int l, int r) const {
		return sub(l, r + 1, 1, 0, n);
	}
	T operator[](int i) const {
		return data[i + n];
	}
};

int N, rt;
vector<int> G[MAX];
int depth[MAX], used[MAX], id[MAX];
vector<int> vs, de;

void Add(int a, int b) {
	G[a].push_back(b);
	G[b].push_back(a);
}

void dfs(int s, int d) {
	used[s] = 1;

	vs.push_back(s);
	de.push_back(d);
	for (int v : G[s]) {
		if (!used[v]) {
			dfs(v, d + 1);

			vs.push_back(s);
			de.push_back(d);
		}
	}
}

SegmentTree<pi> Init() {
	fill(used, used + N, 0);
	fill(id, id + N, -1);
	dfs(rt, 0);
	for (int i = 0; i < (int)vs.size(); i++) {
		if (id[vs[i]] == -1) {
			id[vs[i]] = i;
		}
	}
	vector<pi> r((int)vs.size());
	for (int i = 0; i < (int)vs.size(); i++) {
		r[i] = pi(de[i], vs[i]);
	}
	SegmentTree<pi> res(r, pi(N, -1), [](pi a, pi b) { return a.first <= b.first ? a : b; });
	for (int i = 0; i < N; i++) {
		depth[i] = res[id[i]].first;
	}
	return res;
}

int LCA(const SegmentTree<pi>& st, int a, int b) {
	return st.Find(min(id[a], id[b]), max(id[a], id[b])).second;
}

int main()
{
	cin >> N;
	for (int i = 0, k; i < N; i++) {
		cin >> k;
		for (int j = 0, c; j < k; j++) {
			cin >> c;
			Add(i, c);
		}
	}
	int Q, a, b;
	auto st = Init();
	cin >> Q;
	while (Q--) {
		cin >> a >> b;
		cout << LCA(st, a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 21352
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch RepeatACL | diff RepeatACL.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address RepeatACL.cpp && ./a.out

/*

 9/26/2020

 5:00-

 */

int K;

void solve() {
  string res;
  REP(_,K) res+="ACL";
  cout<<res<<endl;
}

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

  cin>>K;
  solve();

  return 0;
}


Measured memory_bytes: 3616
n, m = map(int, input().split())
aList = list(map(int, input().split()))

k = sum(aList) / (4 * m)
count = 0
flag = False
for i in aList:
    if i >= k:
        count += 1
        if count == m:
            flag = True
            break
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int n,array1[N],i,sum=1,flag=1;
scanf("%d",&n);
set<int>s;
map<int,int>mp;
for(i=0;i<n;++i){
    scanf("%d",&array1[i]);
    int x,y;
    x=((n-1)+array1[i])/2;
    y=(n-1)-x;
    if(x+y==n-1){
        s.insert(array1[i]);
        mp[array1[i]]++;
        if(mp[array1[i]]>2){
            flag=0;
            break;
        }
        if(array1[i]==0&&mp[array1[i]]>1){
            flag=0;
            break;
        }
    }
    else{
        flag=0;
        break;
    }
}
if(flag){
    if(s.find(0)!=s.end()){
        s.erase(0);
    }
    for(i=0;i<s.size();++i){
        sum=(1ll*sum*2)%MOD;
    }
    printf("%d",sum);
}
else{
    printf("0");
}



    return 0;
}


Measured memory_bytes: 8820
#include<bits/stdc++.h>
#define MAXI 1000000000000000000
#define lint long long
using namespace std;

int main(){
	int n;
	lint s=1;
	cin>>n;
	vector<lint> v(n);
	
	for(lint &x:v){
		cin>>x;
		if(x == 0) s=0;
	}
	if(s)
		for(lint &x:v){
			if(s>0 && x > MAXI/s){
				s = -1;
				break;
			}
			s *= x;
		
		}
	cout<<s<<"\n";
;	return 0;
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    if(S[0]!='A'){cout<<"WA"<<endl;exit(0);}
    if(S[1]<'a'||'z'<S[1]){cout<<"WA"<<endl;exit(0);}
    int c=0;
    for(int i=2;i<S.size();i++){
        if((S[i]<'a'||'z'<S[i])&&S[i]!='C'){cout<<"WA"<<endl;exit(0);}
        if(S[i]=='C'&&i!=S.size()-1){c++;}
    }
    if(c!=1){cout<<"WA"<<endl;exit(0);}
    cout<<"AC"<<endl;
}

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

int main(){
  int a,b,cou;
  while(1){
    cin >>a;
    if(a==-1)break;
    b=4;
    for(b=4;b<=a;b=b*4);
    b=b/4;
    while(1){
      cout<< a/b;
      a%=b;
      if(b==1)break;
      b=b/4;
    }
    cout << endl;
  }
  return 0;

}

Measured memory_bytes: 1160
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

trees = [ [] for i in range(n+1) ]
for i in range(n-1):
    a, b = map(int, input().split())
    trees[a].append(b)
    trees[b].append(a)

values = [ 0 for i in range(n+1) ]
for i in range(q):
    p, x = map(int, input().split())
    values[p] += x
#print(values)

def dfs2(i, parent):
    for j in trees[i]:
        if j == parent: continue
        values[j] += values[i]
        dfs2(j, i)

dfs2(1, -1)
print(*values[1:])

Measured memory_bytes: 230888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;

int main() {
  int n; cin >> n;
  map<string, int> mp;
  ll ans = 0;
  rep(i,n){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  for(auto p : mp){
    ans += (ll)p.second*(p.second-1)/2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11368
n,k = map(int,input().split())
a_list = list(map(int,input().split()))
roop_town = None
town_list = [1]
town_set = set([1])
for cur_town in town_list:
    if a_list[cur_town-1] in town_set:
        roop_town = a_list[cur_town-1]
        break
    town_list.append(a_list[cur_town-1])
    town_set.add(a_list[cur_town-1])
if roop_town == None:
    print(town_list[k])
else:
    roop_index = town_list.index(roop_town)
    roop_num = len(town_list) - roop_index
    if k<=roop_index:
        print(town_list[k])
    else:
        k_rooped_index = (k-roop_index)%roop_num
        print(town_list[roop_index+k_rooped_index])

Measured memory_bytes: 32268
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace po {
  class Program {
    static void Main(string[] args) {
      int n = int.Parse(Console.ReadLine());
      string[] s = Console.ReadLine().Split(' ');
      int[] a = s.Select((x) => (int.Parse(x))).ToArray();

      int ans = 1145141919;
      for (int i = -100; i <= 100; ++i) {
        int res = 0;
        for (int j = 0; j < n; ++j) {
          res += (a[j] - i) * (a[j] - i);
        }
        ans = Math.Min(ans, res);
      }
      Console.WriteLine(ans);
    }
  }
}

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

int main() {
  int n=0;
  cin >> n;
  
  long long int a[n+1],b[n],ans=0;
  rep(i,n+1){cin >> a[i];}
  rep(i,n){cin >> b[i];}

  rep(i,n){
    ans += min(a[i],b[i]);
    b[i] -= min(a[i],b[i]);
    ans += min(a[i+1],b[i]);
    a[i+1] -= min(a[i+1],b[i]);
  }
  
  cout << ans;
  
  return 0;

}

Measured memory_bytes: 1792
def hantei(n,m,s,k,p):
  b = 0
  for l in range(m):
    a = 0
    for x in range(k[l][0]):
      a += s[k[l][x+1]-1]
    if a%2 != p[l]:
      b = 1
  if b == 0:
    return True
  else:
    return False

n,m = map(int,input().split())
k = []
for _ in range(m):
  k.append(list(map(int,input().split())))
p = list(map(int,input().split()))
c = 0
for _ in range(2**n):
  s = [0] * n
  ll = len(bin(_))
  for i in range(ll):
    if i >= 2:
      s[n-ll+i] = int(bin(_)[i])
  if hantei(n,m,s,k,p):
    c += 1
print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;

const lint mod = 998244353;
const lint INF = mod * mod;

lint powmod(lint x, lint n){
    lint ret = 1;
    while(n > 0){
        if(n&1) ret *= x, ret %= mod, n -= 1;
        else x *= x, x %= mod, n >>= 1;
    }
    return ret;
}

int main(){
    int n;
    scanf("%d", &n);
    int cnt[100010];
    rep(i, 100010) cnt[i] = 0;
    int d[n];
    rep(i, n){
        scanf("%d", &d[i]);
        ++cnt[d[i]];
    }

    if(cnt[0] != 1 || d[0] != 0){
        printf("%d\n", 0);
        return 0;
    }

    lint ans = 1;
    For(i, 1, 100010)if(cnt[i]){
            (ans *= powmod((lint)cnt[i-1], (lint)cnt[i])) %= mod;
        }
    printf("%lld\n", ans);
}

Measured memory_bytes: 1024
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    K, S = map(int, readline().split())

    ans = 0
    for i in range(K + 1):
        for j in range(K + 1):
            if 0 <= S - i - j <= K:
                ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#define N ()
#define P (1000000007)
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand())<<(15))^(rand()))
#define file(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1{
	inline char read(){
		static const int IN_LEN=1000000;
		static char buf[IN_LEN],*s,*t;
		return (s==t?t=(s=buf)+fread(buf,1,IN_LEN,stdin),(s==t?-1:*s++):*s++);
	}
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=read();!isdigit(c);c=read()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=read())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
	inline char readc(char &c){
		for(c=read();!isalpha(c)&&!isdigit(c);c=read())
		if(c==-1)return 0;
	}
	const int OUT_LEN = 10000000;
	char obuf[OUT_LEN],*ooh=obuf;
	inline void print(char c) {
		if(ooh==obuf+OUT_LEN)fwrite(obuf,1,OUT_LEN,stdout),ooh=obuf;
		*ooh++=c;
	}
	template<class T>
	inline void print(T x){
		static int buf[30],cnt;
		if(x==0)print('0');
		else{
			if(x<0)print('-'),x=-x;
			for(cnt=0;x;x/=10)buf[++cnt]=x%10+48;
			while(cnt)print((char)buf[cnt--]);
		}
	}
	inline void flush(){fwrite(obuf,1,ooh-obuf,stdout);}
}
namespace fastIO2{
	template<class T>
	inline void read(T &x){
		static bool iosig;
		static char c;
		for(iosig=false,c=getchar();!isdigit(c);c=getchar()){
			if(c=='-')iosig=true;
			if(c==-1)return;
		}
		for(x=0;isdigit(c);c=getchar())x=((x+(x<<2))<<1)+(c^'0');
		if(iosig)x=-x;
	}
}
using namespace fastIO1;
int n,m,K,f[2][2010][2],sum[2010],ans;
int main(){
	read(n),read(m),read(K),m--,K--;
	f[0][0][0]=1;
	for(int i=1,p=1;i<=max(n,m)*2;i++,p^=1){
		for(int j=1;j<=n;j++)sum[j]=(0ll+sum[j-1]+f[p^1][j-1][0]+f[p^1][j-1][1])%P;
		for(int j=0;j<=n;j++)
		f[p][j][0]=(sum[j+1]-sum[j]+P)%P,
		f[p][j][1]=(sum[j]-sum[max(0,j-K)]+P)%P;
		for(int j=0;j<=n;j++)
		if(j%K==n%K&&(i*K-j)%K==m%K&&(i*K-j)<=m)(ans+=f[p][j][1])%=P;
	}
	cout<<ans;
}

Measured memory_bytes: 2304
//Circle Pond
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    double R;
    cin >> R;
    printf("%.10f", 3.14159265359f * 2.0f * R);
    return 0;
}

Measured memory_bytes: 3252
n=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            I=l[i]
            J=l[j]
            K=l[k]
            if I+J>K and J+K>I and K+I>J and I!=J and I!=K and J!=K:
                ans+=1
print(ans)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
#include <vector>       // ヘッダファイルインクルード
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    string S;
  cin>>S;
  string divide[4]={"dream","dreamer","erase","eraser"};
  reverse(S.begin(),S.end());
  for(int i=0;i<4;i++) reverse(divide[i].begin(),divide[i].end());
  
  bool can = true;
  for(int i=0;i<S.size();){
    bool can2 = false;
      for(int j=0;j<4;j++){
      string d=divide[j];
      if(S.substr(i,d.size())==d){
      can2=true;
      i+=d.size();}
      }
    if (can2==false){
      can=false;
      break;}
  }
  if(can==true)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
                                                        
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int K;
map<int, bool> used;

signed main()
{
	cin >> K;
	priority_queue<int,vi,greater<int>> q;
	rep1(i, 10)q.push(i);

	int cnt = 0;

	while (q.size()) {
		int v = q.top(); q.pop();
		//printf("v=%lld\n",v);
		int d = v % 10;

		if (used[v]) continue;
		used[v] = true;

		cnt++;
		//printf("v=%lld, cnt=%lld\n",v,cnt);
		if (cnt == K) {
			cout << v << endl;
			return 0;
		}
		if(d-1>=0)q.push(v*10 + d-1);
		q.push(v*10 + d);
		if (d+1<=9)q.push(v*10 + d+1);
	}
}




Measured memory_bytes: 8048
// vim: set fdm=marker:
// {{{
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <utility>

using namespace std ;

typedef long long ll ;

// }}}

char S[222222];
char T[222222];

bool safe(char d1, char d2, int s, int bsize, int N)
{
    int lb = 1, rb = bsize;
    if (S[N-1] == d1)
        lb++;
    if (S[N-1] == d2)
        rb--;
    for (int i = N-2 ; i >= 0 ; i--) {
        if (T[i] == d1) {
            if (rb < bsize) rb++;
        }
        else if (T[i] == d2) {
            if (lb > 1) lb--;
        }
        else {
        }
        if (S[i] == d1) {
            lb++;
        }
        else if (S[i] == d2) {
            rb--;
        }
        else {
        }
        if (lb > rb)
            return false;
    }
    return lb <= s && s <= rb;
}

int main()
{
    int H, W, N;
    int sr, sc;
    cin >> H>> W >> N;
    cin >> sr >> sc;
    cin >> S >> T;
    if (safe('U', 'D', sr, H, N) && safe('L', 'R', sc, W, N))
        puts("YES");
    else
        puts("NO");
    return 0;
}



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

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

string s;

int main() {
  cin >> s;
  prians(s[0] == s[2]);
  return 0;
}

Measured memory_bytes: 256
class Solver:

    def __init__(self):
        pass

    def solve(self, incomess):
        RATE = 380000.0
        y = 0.0
        for (x, u) in incomess:
            if u == 'BTC':
                y += RATE * x
            else:
                y += x
        return y


if __name__ == '__main__':

    solver = Solver()

    incomess = []
    n = int(input())
    for _ in range(n):
        input_split = input().split()
        x = float(input_split[0])
        u = input_split[1]
        incomess.append((x, u))

    y = solver.solve(incomess)
    print(y)


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

bool binarySearch(int A[], int n, int key){
	int left = 0;
	int right = n;
	int mid;
	while (left < right){
		mid = (left + right) / 2;	
		if (A[mid] == key){
			return true;
		} else if (key < A[mid]){
			right = mid;
		} else{
			left = mid + 1;
		}
	}
	return false;
}

int main(){
	int A[100000], q, n, key, cnt=0;
	
	scanf("%d", &n);

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

	scanf("%d", &q);
	for (int i=0; i<q; i++){
		scanf("%d", &key);
		if (binarySearch(A, n, key)) cnt++;
	}
	printf("%d\n", cnt);

	return 0;
}

Measured memory_bytes: 1580
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
 
const int maxN = 1 << 18;

void solve()
{
	string a;
	cin >> a;
	if (a == "MON")
		cout << "6";
	if (a == "TUE")
		cout << "5";
	if (a == "WED")
		cout << "4";
	if (a == "THU")
		cout << "3";
	if (a == "FRI")
		cout << "2";
	if (a == "SAT")
		cout << "1";
	if (a == "SUN")
		cout << "7";
	cout << "\n";
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


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

using namespace std;

typedef long long ll;
string n;
ll K;
ll dp[105][2][5];
ll ans;

int main() {
  cin >> n;
  cin >> K;
  int tt = n[0] - '0';
  dp[0][1][1] = 1;
  dp[0][0][1] = tt - 1;
  dp[0][0][0] = 1;
  
  
 
  for(int i = 1; i < n.size(); i++) {
    ll tmp = n[i] - '0';
    for(int j = 0; j < 2; j++) {
      if(j == 0) {
	for(int k = 0; k < 4; k++) {
	  dp[i][j][k+1] += dp[i-1][j][k] * 9;
	  dp[i][j][k] += dp[i-1][j][k];
	}
      }
      else {
	for(int k = 0; k < 4; k++) {
	if(n[i] == '0') {
	  dp[i][j][k] += dp[i-1][j][k];
	}
	else if(n[i] == '1') {
	  dp[i][j][k+1] += dp[i-1][j][k];
	  dp[i][j-1][k] += dp[i-1][j][k];
	}
	else {
	  dp[i][j][k+1] += dp[i-1][j][k];
	  dp[i][j-1][k+1] += dp[i-1][j][k] * (tmp - 1);
	  dp[i][j-1][k] += dp[i-1][j][k];
	}
	}
      }
    }
  }

  /* for(int i = 0; i < n.size(); i++) {
    for(int j = 0; j < 2; j++) {
      for(int k = 0; k < 4; k++) {
	cout << "dp["<<i<<"]["<<j<<"]["<<k<<"] = "<<dp[i][j][k] << endl;
      }
    }
    }*/
  


  //  cout << dp[n.size()-1][0][K] <<"   "<<dp[n.size()-1][1][K] << endl;
  cout << dp[n.size()-1][0][K] + dp[n.size()-1][1][K] << endl;
}
	  
	  
  
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
int gcd(int x, int y){
    if (y == 0)return x;
    else return gcd(y, x % y);
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int res=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                int g=gcd(i,j);
                g=gcd(g,k);
                res+=g;
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int qpow(int a,int k)
{
	int res=1;
	while(k)
	{
		if(k&1) res=res*a%mod;
		a=a*a%mod;
		k>>=1;
	}
	return res;
}
int n,k;
int cnt[100005];
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	int ans=0;
	for(int i=k;i>=1;i--)
	{
		int num=k/i;
		cnt[i]=qpow(num,n);
		for(int j=i*2;j<=k;j+=i)
			cnt[i]=(cnt[i]-cnt[j]+mod)%mod;
		ans=(ans+i*cnt[i])%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4368
#include<iostream>
#include<set>
#include<string>
using namespace std;
int main()
{
  int n,i;
  cin>>n;
  set <string> S;
  string s;
  for(i=0 ; i<n ; i++)
  {
     cin>>s;
    S.insert(s);
  }
  cout<<S.size();
    
  
}

Measured memory_bytes: 19136
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {
    int N;
    double ans = 0;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        ans += 1 / (double)a;
    }
    printf("%.8lf\n", 1 / ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define NUM_MAX 100
#define K_MAX 100000
#define BUF_SIZE (NUM_MAX*7+50)

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

#define DIVISOR 1000000007
#define max(a,b) ((a) > (b) ? (a) : (b))

int main(void) {
    int num, klimit;
    static int arr[NUM_MAX];
    get_int2(&num, &klimit);
    fget_array(arr, num);
    static uint64_t dp[NUM_MAX+1][K_MAX+1];
    int i, k;
    for(i = 0; i <= NUM_MAX; i++) {
        dp[i][0] = 1;
    }

    static uint64_t cum[NUM_MAX+1][K_MAX+2];
    for(i = 1; i <= num; i++) {
        int a = arr[i-1];
        // calc cum[i] for reducing complexity
        for(k = 1; k <= klimit+1; k++) {
            cum[i][k] = (cum[i][k-1] + dp[i-1][k-1])%DIVISOR;
        }
        for(k = 1; k <= klimit; k++) {
            // calc [k-a, k] -> [k-a, k+1)
            int llimit = max(0, k-a);
            // dp[i][k] += dp[i-1][k-j] for j \in [0, a]
            dp[i][k] = (dp[i][k] + cum[i][k+1] + DIVISOR - cum[i][llimit])%DIVISOR;
        }
#ifdef DEBUG
        printf("%d : %llu\n", (int)dp[i][klimit], cum[i][klimit]);
#endif
    }
    printf("%d\n", (int)dp[num][klimit]);
    return 0;
}

Measured memory_bytes: 157184