akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);++i)
#define ROF(i,x) for(int i = (x) ; i >= 0 ; --i)
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ODD(x) (((x)&1)==0?(0):(1))
#define sign(x) ((x > 0) - (x < 0))
std::mt19937_64  generator(std::chrono::system_clock::now().time_since_epoch().count());

inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; }
ll lcm(ll a, ll b) { return a / gcd(a,b) * b; }


void READ(bool _local){
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _DEBUG
    if (_local)
        freopen ("in.txt", "r", stdin);
#endif
}

int main() {
    READ(0);
    int a,b;cin>>a>>b;
    int cnt=1;
    int ret=0;
    while(cnt<b){
        cnt += (a-1);
        ++ret;
    }
    cout << ret;
    return 0;
}



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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int n;
vec<int> v;

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

int main() {
   cin >> n;
   rep (i, 0, n) {
      int x;
      cin >> x;
      v.push_back(x);
   }
   sort(all(v));

   int q;
   cin >> q;
   int cnt = 0;
   rep (i, 0, q) {
      int x;
      cin >> x;
      if (bin(x)) cnt++;
   }
   cout << cnt << endl;

   return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define inf 10000000000

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

    char c;
    cin >> c;
    cout << ((c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') ? "vowel" : "consonant") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void print(int sequence[], int N); // 出力するための関数
void insertionSort(int sequence[], int N); //挿入ソートの関数

int main(void){
    
    // 定義：数列を「 sequence 」、数列の個数を「 N 」と置く
    int sequence[100], N;

    cin >> N;
    
    // 反復：数列に値を入力する
    for(int i = 0; i < N; i++){
        cin >> sequence[i];
    }
    
    print(sequence, N); // 出力するための関数
    insertionSort(sequence, N); //挿入ソートの関数
    
    
}


/***********************  出力するための関数   ******************************/

void print(int sequence[], int N){
    for(int i = 0; i < N; i++){
        cout << sequence[i] << ((i != N-1) ? " " : "\n");
    }
}


/***********************  挿入ソートの関数  ******************************/

void insertionSort(int sequence[], int N){
    
    // 定義：一時保存の箱「 saveBox 」と置く
    int saveBox;
    
    // 反復：未ソートの範囲
    for(int i = 1; i < N; i++){
        saveBox = sequence[i];
        // 定義：ソート済の範囲を「 j 」と置く
        int j = i - 1;
        
        // 反復：一つ横の配列に移動ができるまで繰り返す（比較：配列「０」以上 かつ 配列「j」が saveBox より小さい  とき移動させたい）
        while(j >= 0 && sequence[j] > saveBox){
            sequence[j+1] = sequence[j];
            j--;
        }
        // 上の反復が出来ない ➡  移動が終了でその所が交換したい所
        sequence[j+1] = saveBox;
        
        print(sequence, N); // 出力するための関数
    }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;

signed main() {
    
    cout << fixed << setprecision(6);
  double R;
  cin >> R;
  
  double pi = 3.1415926535;
  cout << 2.0*R*pi << endl;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pi pair<int,int>
#define pl pair<ll, ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const ll N = 2e5 + 5, mod = 1e9 + 7;
const ll inf = 1e18;

bool cmp(const pair<ll, ll> &a, const pair<ll, ll> &b){
    if(a.F == b.F) return a.S < b.S;
    return a.F > b.F;
}
ll power(ll x, ll p){
    ll r = 1ll;
    x = x % mod;
    while(p > 0){
        if(p & 1) r = (r * x) % mod;
        p = p >> 1;
        x = (x * x) % mod;
    }
    return r;
}

void solve(){
    ll k;
    cin >> k;
    ll ans = 0, t = 1;
    for(ll i = 0; i < 2 * k; i++){
        ll l = (t * 7) % k;
        ans = (ans + l) % k;
        if(ans == 0){
            cout << i + 1 << endl;
            return;
        }
        t = (t * 10) % k;
    }
    cout << -1 << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    /*#ifndef ONLINE_JUDGE
        freopen("Input.txt", "r", stdin);
    #endif*/
    //freopen("running_on_fumes_chapter_1_input (1).txt", "r", stdin);
    //freopen("Output.txt", "w", stdout);
    int t = 1, p;
    //cin >> t;
    for(p = 1; p <= t; p++){
        //cout << "Case #" << p << ": ";
        solve();
    }
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(void){
    string str;
    cin>>str;
    int ch[4];
    for (int i=0;i<(int)str.size();++i){
        ch[i]=str[i];
    }
    if (ch[0] == ch[1]){
        if (ch[2]==ch[3] && ch[0]!=ch[2]){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    else if (ch[0] == ch[2]){
        if (ch[1]==ch[3]){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    else if (ch[0] == ch[3]){
        if (ch[1]==ch[2]){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int a, b, c, d;
        a = in.nextInt();
        b = in.nextInt();
        c = in.nextInt();
        d = in.nextInt();
        a += b;
        c += d;
        if (a == c) System.out.println("Balanced");
        else if (a > c) System.out.println("Left");
        else System.out.println("Right");
    }
}

Measured memory_bytes: 21844
//by ysgs
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define sqr(x) ((x)*(x))
    #define mp make_pair
    #define uint unsigned
    inline char gc(){
        static char buf[100000],*p1=buf,*p2=buf;
        return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
    }
    #define gc getchar
    inline int read(){
    	int x = 0; char ch = gc(); bool positive = 1;
    	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
    	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
    	return positive ? x : -x;
    }
    inline void write(int a){
        if(a>=10)write(a/10);
        putchar('0'+a%10);
    }
    inline void writeln(int a){
        if(a<0){
        	a=-a; putchar('-');
    	}
    	write(a); puts("");
    }
    const int N=100005;
    vector<int> v[N];
    int n,color[N];
    void insert(int a,int b){
    	v[a].push_back(b); v[b].push_back(a);
    }
    struct tree{
    	vector<int> v[N];
    	int vis[N],rt;
    	void dfs(int p){
    		if(v[p].size()%2==0)vis[p]=p;
    		for(unsigned i=0;i<v[p].size();i++){dfs(v[p][i]); if(vis[p]){insert(vis[v[p][i]],vis[p]); vis[p]=0;}else vis[p]=vis[v[p][i]];}
    	}
    	void init(){
    		for(int i=1;i<=n;i++){	
    			int t=read(); if(t==-1)rt=i; else v[t].push_back(i);
    		}
    		dfs(rt);
    	}
    }T[2];
    void ddd(int p,bool dq){
    	color[p]=dq;
    	for(unsigned i=0;i<v[p].size();i++)if(color[v[p][i]]==-1)ddd(v[p][i],dq^1);
    }
    int main(){
    	n=read();
    	T[0].init();
    	T[1].init();
    	for(int i=1;i<=n;i++)if(((T[0].v[i]).size())%2!=((T[1].v[i]).size())%2){
    		puts("IMPOSSIBLE"); return 0;
    	}
    	puts("POSSIBLE");
    	memset(color,-1,sizeof(color));
    	for(int i=1;i<=n;i++)if(color[i]==-1)ddd(i,0);
    	for(int i=1;i<=n;i++)if(T[0].v[i].size()&1){
    		putchar('0'); putchar(' ');
    	}else{
    		if(color[i])putchar('-'); putchar('1'); putchar(' ');
    	}
    }


Measured memory_bytes: 18816
function count(n) {
    var c = 0;
    while (n % 2 === 0) {
        n = Math.floor(n / 2);
        c += 1;
    }
    return c;
}

function Main(inp) {
    var input = inp.split("\n");
    var n = Number(input[0]);
    var max = 0;
    var r = 1;
    for (var i = 1; i <= n; i++) {
        var c = count(i);
        if (c > max) {
            max = c;
            r = i;
        }
    }
    console.log(r);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
  int n;
  cin>>n;
  n*=2;
  int l[n];
  int ans=0;
  for(int i=0;i<n;i++)
    cin>>l[i];
  sort(l,l+n);
  for(int i=0;i<n;i++)
    if(i%2==0)
      ans+=l[i];
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//to set precision use fixed,setprecision(number_of_points_after_decimal)
#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 mod 1000000007
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define pb push_back
#define debugvector(h) for(auto &l:h)cout<<l<<" "
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef long double ld;
void solution(){
  int n;cin>>n;
  vi given;
  int x,y,z;cin>>x>>y>>z;
  given.pb(x),given.pb(y),given.pb(z);
  vi dp_prev(3);
  dp_prev[0]=x,dp_prev[1]=y,dp_prev[2]=z;
  rep(i,1,n){
    vi current_dp(3,0);
    cin>>given[0]>>given[1]>>given[2];

    current_dp[0]=given[0]+ max(dp_prev[1],dp_prev[2]);
    current_dp[1]=given[1]+ max(dp_prev[0],dp_prev[2]);
    current_dp[2]=given[2]+ max(dp_prev[0],dp_prev[1]);
    dp_prev=current_dp;
  }
  cout<<max(dp_prev[0],max(dp_prev[1],dp_prev[2]))<<endl;
}



int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
  #endif
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  //int t;cin>>t;
  //while(t--){
  solution();
  //}
  return 0;
}

Measured memory_bytes: 3596
N,M=map(int,input().split())
graph=[[] for i in range(N+1)]
for _ in range(M):
    a,b,weight=map(int,input().split())
    graph[a].append((b,-weight))
    
class Node():
    def __init__(self,name):
        self.name=name
        self.par=None
        self.d=float("inf")
        
    def relax(self,other,weight):
        if self.d>other.d+weight:
            self.d=other.d+weight
            self.par=other.name
    def relax_(self,other,weight):
         if self.d>other.d+weight:
            self.d=other.d+weight
            return True
         return False
def bellman_ford(graph,s_node):
    N=len(graph)-1
    d_list=[Node(i) for i in range(N+1)]
    #初期化
    d_list[s_node].d=0
    for _ in range(N-1):
        #N回同じループを繰り返す
        for node in range(1,N+1):
            for tuple_ in graph[node]:
                point,distance=tuple_
                d_list[point].relax(d_list[node],distance)
    negative=[False for i in range(N+1)]
    for _ in range(N-1):
        #N回同じループを繰り返す
        for node in range(1,N+1):
            for tuple_ in graph[node]:
                point,distance=tuple_
                if d_list[point].relax_(d_list[node],distance):
                    if negative[point]==False:
                        negative[point]=True
                    else:
                        for que in graph[point]:
                            negative[que[0]]=True
    if negative[N]:
        return False

    return d_list[N].d

K=bellman_ford(graph,1)
if K!=False:
    print(-K)
else:
    print("inf")


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

#define MAX 10000
int main(){
	int a[MAX];
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int sum=0, ans=0;

		for(int i=0;i<n;i++){
			cin>>a[i];
			sum+=a[i];
		}
		sum=sum/n;
		for(int i=0;i<n;i++){
			if(a[i]<=sum) ans++;
		}

		cout<<ans<<endl;
	}

	return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <algorithm>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main(){
  string s; //整数の数
  cin >> s;
  char *c = new char[3];
  for(int i=0; i<3; i++){
    c[i] = s.at(i);
  }
  
  if(c[0] == c[1] && c[1] == c[2]){
    cout << "No";
    return 0;
  }else{
    cout << "Yes";
    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
map<char, bool> mp;
int main(int argc, char const *argv[])
{
    string s, t;
    cin >> s >> t;
    rep(i, s.size())
    {
        mp[s[i]] = true;
    }
    rep(i, t.size())
    {
        if (mp[t[i]] == false)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    map<char, vector<int>> pos;

    rep(i, s.size())
    {
        pos[s[i]].push_back(i);
    }
    int cnt = 0;
    int now = 0;
    int onelast = 0;
    while (now < t.size())
    {
        int i = 0; //*lower_bound(ALL(pos[t[now]]), 0);
        while (true)
        {
            if (t[now] == s[i])
            {

                now++;
                i++;
                if (now == t.size())
                {
                    onelast = i;
                    cnt++;
                    //cerr << "*" << 1 << endl;

                    break;
                }
            }
            else
            {
                //cerr << "n " << now << endl;
                auto itr = lower_bound(ALL(pos[t[now]]), i);
                if (itr == pos[t[now]].end())
                {
                    //  cerr << "*" << 2 << endl;
                    cnt++;
                    break;
                }
                //cerr << "c " << *itr << endl;
                i = *itr;
            }
        }
        //cnt++;
    }
    //cerr << cnt << endl;
    cout << s.size() * (cnt - 1) + onelast << endl;

    return 0;
}


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

const int mod = 998244353;
int GM(int x){
    return x >= mod? x-mod : x;
}

int main()
{
    int n;;
    scanf("%d",&n);
    vector <pair<int ,int>> robs(n);
    for(auto&r : robs)
        scanf("%d%d",&r.first,&r.second);
    sort(robs.begin() ,robs.end());

    vector <int> to(n); to[n-1] = n;
    deque <int> dq{n-1};
    for(int i=n-2; ~i; i--){
        int rch = lower_bound(robs.begin() ,robs.end() ,make_pair(robs[i].first+robs[i].second ,-1))-robs.begin()-1;
        to[i] = rch+1;
        if(i < rch)
            to[i] = max(to[i] ,to[*prev(upper_bound(dq.begin() ,dq.end() ,rch))]);
        while(!dq.empty() && to[dq.front()] <= to[i])
            dq.pop_front();
        dq.push_front(i);
    }

    vector <int> dp(n+1); dp[n] = 1;
    for(int i=n-1; ~i; i--)
        dp[i] = GM(dp[i+1]+dp[to[i]]);
    printf("%d\n",dp[0]);
}


Measured memory_bytes: 3840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            List<String> firstRow = Arrays.asList(br.readLine().split(""));
            List<String> secondRow = Arrays.asList(br.readLine().split(""));

            StringBuilder ans = new StringBuilder();

            if (firstRow.size() > secondRow.size()) {
                for (int i = 0; i < secondRow.size(); i++) {
                    ans.append(firstRow.get(i)).append(secondRow.get(i));
                    if (i == secondRow.size() - 1) {
                        ans.append(firstRow.get(i + 1));
                    }
                }
            } else if (firstRow.size() < secondRow.size()) {
                for (int i = 0; i < firstRow.size(); i++) {
                    ans.append(firstRow.get(i)).append(secondRow.get(i));
                    if (i == firstRow.size() - 1) {
                        ans.append(secondRow.get(i + 1));
                    }
                }
            } else if (firstRow.size() == secondRow.size()) {
                for (int i = 0; i < firstRow.size(); i++) {
                    ans.append(firstRow.get(i)).append(secondRow.get(i));
                }
            }

            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

int main() {

    int n,m;

    cin >> n >> m;

    int table[n+1][n+1];

    for(int i=0; i<n+1; i++){
        for(int j=0; j<n+1; j++){
            table[i][j] = 10000000;
        }
    }

    for(int i=0; i<n+1; i++){
        table[i][i] = 0;
    }

    int to[m],from[m],cost[m];

    for(int i=0; i<m; i++){

        int a,b,c;

        cin >> a >> b >> c;

        to[i] = a;
        from[i] = b;
        cost[i] = c;

        table[a][b] = c;
        table[b][a] = c;
    }

    for(int k=1; k<=n; k++){
        for(int i=1; i<=n; i++){
            for(int j=1; j<=n; j++){
                table[i][j] = min(table[i][j],table[i][k] + table[k][j]);
            }
        }
    }

    int ans = 0;

    for(int i=0; i<m; i++){
        bool used = false;
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                if(table[j][k] == table[j][to[i]] + cost[i] + table[from[i]][k]){
                    used = true;
                }
                if(table[j][k] == table[j][from[i]] + cost[i] + table[to[i]][k]){
                    used = true;
                }
            }
        }
        if(!used){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>
#include <cfloat>

using namespace std;



int main(int argc, const char * argv[]) {

    
    int n;
    cin >> n;
    
    int x[n],y[n];
    
    for(int i=0; i<n; i++)
        cin >> x[i];
    for(int i=0; i<n; i++)
        cin >> y[i];

    double p1,p2,p3,pm;

    //p=1のとき
    p1 = 0.0;
    p2 = 0.0;
    p3 = 0.0;
    
    pm = DBL_MIN;
    
    for(int i=0; i<n; i++){
        p1 += fabs(x[i]-y[i]);
        p2 += (x[i]-y[i])*(x[i]-y[i]);
        p3 += fabs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
        
        if(pm < fabs(x[i]-y[i]))
            pm = fabs(x[i]-y[i]);
        
    }
    
    printf("%5f\n",p1);
 
    //p=2のとき
    printf("%5f\n",sqrt(p2));

    //p=3のとき
    printf("%5f\n",pow(p3,(1.0/3.0)));

    
    printf("%5f\n",pm);

    
    return 0;
}



Measured memory_bytes: 3336
use std::io;

fn main() {
    let n = input_number();
    let n = n[0];
    let mut s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
    let mut h = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
    let mut c = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
    let mut d = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];

    for _ in 0..n {
        let (pattern, number) = input();
        match pattern {
            'S' => s[number - 1] = 0,
            'H' => h[number - 1] = 0,
            'C' => c[number - 1] = 0,
            'D' => d[number - 1] = 0,
            _ => println!("error!"),
        }
    }
    for value in &s {
        if *value != 0 { println!("S {}", value); }
    }
    for value in &h {
        if *value != 0 { println!("H {}", value); }
    }
    for value in &c {
        if *value != 0 { println!("C {}", value); }
    }
    for value in &d {
        if *value != 0 { println!("D {}", value); }
    }
}

#[allow(dead_code)]
fn input_number() -> Vec<i64> {
    let mut input = String::new();
    io::stdin().read_line(&mut input) .expect("Failed to read line");
    let vec: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (char, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c:char = iter.next().unwrap().chars().nth(0).unwrap();
    let n:usize = iter.next().unwrap().parse().unwrap();
    (c, n)
}



Measured memory_bytes: 5036
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;
using VVVI = vector <VVI>;

struct QueNode {
    int qx;
    int qy;
    int dist;
    int dir;

    QueNode(int px, int py,  int pdir, int pdist) : qx(px), qy(py), dist(pdist), dir(pdir) {
    }

    bool operator<(const QueNode& q) const {
        return dist > q.dist;
    }
};

int main() {
    int H;
    int W;
    int K;

    cin >> H >> W >> K;

    vector <string> pond(H);
    VVVI dp(H, VVI(W, VI(4, -1)));

    VI x(2);
    VI y(2);
    for (int i = 0; i < 2; ++i) {
        cin >> x[i] >> y[i];
        --x[i];
        --y[i];
    }

    for (int i = 0; i < H; ++i) {
        cin >> pond[i];
    }

    priority_queue <QueNode> que;
    dp[x[0]][y[0]][0] = 0;
    que.push(QueNode(x[0], y[0], 0, 0));

    while (!que.empty()) {
        int qx = que.top().qx;
        int qy = que.top().qy;
        int qdir = que.top().dir;
        int qdist = que.top().dist;

        que.pop();

        if (qdist > dp[qx][qy][qdir]) {
            continue;
        }

        if (qx == x[1] && qy == y[1]) {
            break;
        }

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

        for (int dir = 0; dir < 4; ++dir) {
            int nqx = qx + dx[dir];
            int nqy = qy + dy[dir];
            int nd = (dir == qdir) ? dp[qx][qy][qdir] + 1 : (((dp[qx][qy][qdir]+K-1)/K)*K) + 1;

            if (nqx >= 0 && nqx < H
                && nqy >= 0 && nqy < W) {
                if (pond[nqx][nqy] != '@' && (dp[nqx][nqy][dir] == -1 || nd < dp[nqx][nqy][dir])) {
                    dp[nqx][nqy][dir] = nd;
                    que.push(QueNode(nqx, nqy, dir, nd));
                }
            }
        }
    }

    const int MAXVAL = 1000000010;
    int ans = MAXVAL;

    for (int dir = 0; dir < 4; ++dir) {
        if (dp[x[1]][y[1]][dir] > 0) {
            ans = min(ans, dp[x[1]][y[1]][dir]);
        }
    }

    cout << (ans == MAXVAL ? -1 : (ans+K-1)/K) << endl;

    return 0;
}

Measured memory_bytes: 112440
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
char str[110][110];
int dx[]={1,0,0,-1};
int dy[]={0,1,-1,0};
int bfs[110][110][11][11][4];
struct wolf{
	int r,c,a,b,d;
	wolf(){}
	wolf(int R,int C,int A,int B,int D){r=R;c=C;a=A;b=B;d=D;}
};
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	int sr,sc,gr,gc;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(str[i][j]=='S'){sr=i;sc=j;}
		if(str[i][j]=='G'){gr=i;gc=j;}
	}
	queue<wolf>Q;
	//for(int i=0;i<4;i++){
		bfs[sr][sc][0][0][0]=1;
		Q.push(wolf(sr,sc,0,0,0));
	//}
	while(Q.size()){
		wolf at=Q.front();
		Q.pop();
		int tr=at.r+dx[at.d];
		int tc=at.c+dy[at.d];
		if(tr<0||tc<0||tr>=a||tc>=b||str[tr][tc]=='#')continue;
		if(tr==sr&&tc==sc&&at.d==3)continue;
		if(!bfs[tr][tc][at.a][at.b][at.d]){
			bfs[tr][tc][at.a][at.b][at.d]=1;
			Q.push(wolf(tr,tc,at.a,at.b,at.d));
		}
		if((tr!=sr||tc!=sc)&&at.a<c&&!bfs[tr][tc][at.a+1][at.b][at.d^1]){
			int td=at.d^1;
			bfs[tr][tc][at.a+1][at.b][td]=1;
			Q.push(wolf(tr,tc,at.a+1,at.b,td));
		}
		if((tr!=sr||tc!=sc)&&at.b<c&&!bfs[tr][tc][at.a][at.b+1][at.d^2]){
			int td=at.d^2;
			bfs[tr][tc][at.a][at.b+1][td]=1;
			Q.push(wolf(tr,tc,at.a,at.b+1,td));
		}
	}
	int ret=999999;
	for(int i=0;i<=c;i++)for(int j=0;j<=c;j++)for(int k=0;k<4;k++)
		if(bfs[gr][gc][i][j][k])ret=min(ret,i+j);
	if(ret<9999)printf("%d\n",ret);
	else printf("-1\n");
}

Measured memory_bytes: 20304
from collections import Counter
n, m = map(int, input().split())
a = Counter(list(map(int, input().split())))

for i in range(m):
    b, c = map(int, input().split())
    a[c] += b

num = sorted(a.items(), key=lambda x: x[0], reverse=True)
ans = 0

for key, val in num:
    if n > val:
        ans += key * val
        n -= val
    else:
        ans += key * n
        break

print(ans)

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    
    int ac_num=0;
    int wa_num=0;
    vector<bool> AoW(N+1, false);
    vector<int> pen(N+1, 0);
    for(int m=0; m<M; m++) {
        int p;
        string S;
        cin >> p >> S;
        if(!AoW[p]) {
            if(S=="WA") {
                pen[p]++;
            } else {
                ac_num++;
                
                wa_num+=pen[p];
                AoW[p]=true;
            }
        }
    }
    
    cout << ac_num << " " << wa_num << endl;


    return 0;
    
}

Measured memory_bytes: 768
#include<cstdio>
using namespace std;

int main(){
  int a,b,flag;
  char s[101][101];
  scanf("%d %d",&a,&b);
  for(int i=0;i<100;i++)
    for(int j=0;j<=100;j++){
      if(j==100)
        s[i][j]='\0';
      else if(i<50)
        s[i][j]='#';
      else
        s[i][j]='.';
    }
  a--;
  b--;
  for(int i=1;i<49;i++)
    for(int j=1;j<99;j++){
      if(a>0){
        flag=1;
        for(int di=-1;di<=1;di++)
          for(int dj=-1;dj<=1;dj++)
            if(s[i+di][j+dj]=='.')
              flag=0;
        if(flag){
          s[i][j]='.';
          a--;
        }
      }
    }
  for(int i=51;i<99;i++)
    for(int j=1;j<99;j++){
      if(b>0){
        flag=1;
        for(int di=-1;di<=1;di++)
          for(int dj=-1;dj<=1;dj++)
            if(s[i+di][j+dj]=='#')
              flag=0;
        if(flag){
          s[i][j]='#';
          b--;
        }
      }
    }
  printf("100 100\n");
  for(int i=0;i<100;i++)
    printf("%s\n",s[i]);
}

Measured memory_bytes: 128
/**
*    created: 12.05.2020 00:58:50
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    auto f = [&](int i) {
        int j = i - i/c - i/d + i/(c*d/__gcd(c,d));
        return j;
    };
    cout << f(b) - f(a-1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int d,l;
  int count = 0;
  cin>>d>>l;
  if(d%l==0){
    cout<<d/l<<endl;
  }
  else{
    for(;d>l;d-=l){
      count++;
    }
    cout<<count+d<<endl;
  }
}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("input.txt","w",stdout);

    int a,b;
    cin >> a >> b;
    int cnt=1,ans=0;
    a--;
    while(cnt < b)
    {
        cnt+=a;
        ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string.h>
using namespace std;

#define HUNDRED 100
#define THOUSAND 10000
#define TENTHOUSAND 10000
#define HUNDREDTHOUSAND 100000

int main() {
	int k, s;
	int x, y, z;
	int ans_cout = 0;

	cin >> k >> s;

	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			x = i;
			y = j;
			if (((z = s - x - y) <= k) && (z >= 0)) {
				ans_cout++;
			}
		}
	}

	cout << ans_cout;

}


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

int main()
{
    int K, S;
    cin >> K >> S;
    int ans=0;
    for(int x=0; x<=K; x++){
        for(int y=0; y<=K; y++){
            int tmp=S-x-y;
            if(tmp>=0 && tmp<=K){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000
#define ll long long int
using namespace std;

/*
vector <int> dx = {1,0,-1,0};
vector <int> dy = {0,1,0,-1};

*/

bitset  <13> result;

ll to_int(string s){
  ll ans = atol(s.c_str());

  return ans;
}

int main(){
  string s;
  cin>>s;

  ll ans=0;

  for(int i=0;i<pow(2,s.size()-1);i++){

    bitset <13> bitflag = i;

    ll preans = 0;

    string part;
    part += s[0];
    preans += to_int(part);
    part.clear();

    for(int j=1;j<s.size();j++){

      if(bitflag[j-1] == 1){
        part += s[j];
        preans += to_int(part);
        part.clear();
       // part += s[j];
      } else{
        part += s[j];
        preans -= to_int(part);
        part.clear();
      }

    }

    if(preans == 7) {
      result = bitflag;
      break;
    }
    part.clear();
  }

  cout<<s[0];
for(int i=0;i<=2;i++){
  if(result[i] == 1){
    cout<<'+';
  } else {
    cout<<'-';
  }
  cout<<s[i+1];
}
cout<<"=7";
cout<<endl;





  return 0;
}

Measured memory_bytes: 256
#include<iostream>
//2^n-1-nCa-nCb
using namespace std;

const long long MOD = 1000000007;

long long binary_power(long long a, long long b) //a^b
{
    if(b==0) return 1;
    else if(b % 2==0)
    {
        long long d = binary_power(a,b/2);
        return (d*d) % MOD;
    }
    else
    {
        return (a * binary_power(a,b-1))%MOD;
    }
    
}

long long fact(long long n) //n!
{
    long long t=1;
    for(long long i=1;i<=n;++i)
    {
        t=(t*i) %MOD;
    }
    return t;
}

long long Permutation(long long n,long long a) //nPa
{
    long long t=1;
    for(long long i=0;i<a;++i)
    {
        t= t * (n-i) % MOD;
    }

    for(long long i=1;i<=a;i++)
    {
        t = t * binary_power(i,MOD-2)%MOD;
    }
    return t;
}
int main()
{
    long long n,a,b;cin >> n >> a >>b;

    long long s = binary_power(2,n) -1; // 2^n-1 
    long long nCa = Permutation(n,a);
    long long nCb = Permutation(n,b);
    cout << (s-nCa-nCb+2*MOD)%MOD<<endl;
}

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

int main() {

	int N;
	cin >> N;
 	string res = "No";
  
     for(int i=0; i<=N/4; i++){
        for(int j=0; j<=N/7; j++){
         int price = i*4 + j*7;
         if(price == N){
           res = "Yes";
           i = N/4+1;
           break;
         }
         if(price > N){
           break;
         }
       }
      }
  
    cout << res << endl;
 
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,K = map(int,readline().split())
A = np.array(read().split(),np.int64)
MOD = 10 ** 9 + 7

def cumprod(A, MOD = MOD):
    L = len(A); Lsq = int(L**.5+1)
    A = np.resize(A, Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        A[:,n] *= A[:,n-1]; A[:,n] %= MOD
    for n in range(1,Lsq):
        A[n] *= A[n-1,-1]; A[n] %= MOD
    return A.ravel()[:L]
def make_fact(U, MOD = MOD):
    x = np.arange(U, dtype = np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact,fact_inv

fact, fact_inv = make_fact(10 ** 5 + 100)

A.sort()
coef = (fact[K-1:N] * fact_inv[K-1] % MOD * fact_inv[0:N-K+1] % MOD)[::-1]

answer = ((A[::-1][:N-K+1] - A[:N-K+1]) * coef % MOD).sum() % MOD
print(answer)

Measured memory_bytes: 24752
H, W = list(map(int, input().split()))
M = int(input())
A = list(map(int, input().split()))

C = [[0 for _ in range(W)] for l in range(H)]

back = 1
c = 1
count = 0
for i in range(H):
  for j in range(W)[::back]:
    C[i][j] = c
    count+=1
    if count == A[c-1]:
      c += 1
      count = 0

  back = -back

for c in C:
  print(" ".join(map(str, c)))

Measured memory_bytes: 39792
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,s,x,y,z,cnt=0;
    cin>>k>>s;
    for(int i =0;i <=k;i++){
        for(int j =0;j <=k;j++){
            int m = s-i-j;
            if(0<=m && m<=k){
                cnt++;
            }
        }
    }
    cout<<cnt<<endl;




    }




















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

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long llint;

const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 10;

char s[MAXN];

int main(void) {
  scanf("%s", s);
  int n = strlen(s);
  for (int i = 0; i < n; ++i)
    if (s[i] == '?') s[i] = 'D';
  printf("%s\n", s);
  return 0;
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

ll mod =1000000007;
long long funk(int i){
  if(i==0) return 1;
  return funk(i-1)*i % mod ;
}
int main(){
  int N; cin >> N;
  cout << funk(N) << endl;
}
  

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

template<class Abel> struct PUnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    PUnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
  int N,M;
  cin>>N>>M;
  vector<vector<int>> v(M,vector<int>(3));
  for(int i = 0; i < M; i++) cin>>v[i][0]>>v[i][1]>>v[i][2];
  PUnionFind<int> tree;
  tree.init(N);
  bool can = true;
  for(int i = 0; i < M; i++){
    int x = v[i][0]-1,y=v[i][1]-1,cost=v[i][2];
    if(tree.issame(x,y)){
      if(tree.diff(x,y)!=cost) can = false;
    }
    else {
      tree.merge(x,y,cost);
    }
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  

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

using namespace std;
using ll = long long;

ll gcd(ll a,ll b){while(a&&b){if(a>b) a = a%b;else b = b%a;}return a+b;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

int main()
{
    ll n, m; cin >> n >> m;
    vector<ll> a(n); for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] /= 2;
    }

    ll lc = 1;
    for(int i = 0; i < n; i++){
        lc = lcm(lc, a[i]);
        if(lc > m) {
            cout << 0 << endl;
            return 0;
        }
    }
    int lcnt = 0, lctmp = lc;
    while(lctmp % 2 == 0) {
        lctmp /= 2;
        lcnt++;
    }
    for(int i = 0; i < n; i++) {
        int cnt = 0;
        while(a[i] % 2 == 0) {
            a[i] /= 2;
            cnt++;
        }
        if(cnt != lcnt) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << (m / lc) - (m / (lc * 2)) << endl;

}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static double solve(int n, int[] prob) {
      int limit = 301;
      double[][][] dp = new double[limit][limit][limit];
      
      for(int i = 0; i < limit; i++) {
        for(int j = 0; j < limit; j++) {
          for(int k = 0; k < limit; k++) {
            dp[i][j][k] = -1;
          }
        }
      }
      
      double result = dfs(dp, n, prob[1],prob[2],prob[3]);
      
      return result;
    }
  
  	private static double dfs (double[][][] dp, int n, int a, int b, int c){
      if(a == 0 && b ==0 && c ==0){
        return 0;
      }
      if(dp[a][b][c] != -1) {
        return dp[a][b][c];
      }
      
      double prob = (double) n / (a + b + c);
      double result = 0;
      
      if(a > 0){
        result += (prob + dfs(dp, n, a - 1, b, c)) * a / (a + b + c);
      }
      if(b > 0){
        result += (prob + dfs(dp, n, a + 1, b - 1,c)) * b / (a + b + c);
      }
      if(c > 0){
        result += (prob + dfs(dp, n, a, b + 1,c-1)) * c / (a + b + c); 
      }
      
      dp[a][b][c] = result;
      return result;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        
      	int[] vals = new int[4];
        for (int i = 0; i < n; i++) {
          int val = scanner.nextInt();
          vals[val]++;
        }

      	double result = solve(n, vals);
      
        System.out.println(result);
    }
}


Measured memory_bytes: 309712
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define rep(i,n) for(ll i=0;i<n;i++)
typedef long long ll;
using namespace std;

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}

void chmax(ll &a,const ll &b){
    if(a<b) a=b;
}
void chmin(ll &a,const ll &b){
    if(a>b) a=b;
}


int main()
{
    string S,T;

    cin >> S >> T;

    ll s=S.length(),t=T.length();

    ll dp[s][t];


    rep(i,s){
        rep(j,t){
            if(i==0 && j==0){
                if(S[i]==T[j]){
                    dp[i][j]=1;
                }else{
                    dp[i][j]=0;
                }
            }else if(i==0 && j!=0){
                if(dp[i][j-1]==1){
                    dp[i][j]=1;
                }else if(S[i]==T[j]){
                    dp[i][j]=1;
                }else{
                    dp[i][j]=0;
                }
            }else if(i!=0 && j==0){
                if(dp[i-1][j]==1){
                    dp[i][j]=1;
                }else if(S[i]==T[j]){
                    dp[i][j]=1;
                }else{
                    dp[i][j]=0;
                }                
            }else{
                if(S[i]==T[j]){
                    dp[i][j]=dp[i-1][j-1]+1;
                }else{
                    dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }        
        }
    }

    string ans="";
    ll i=s-1,j=t-1;

    while(dp[i][j]>0 && i>=1 && j>=1    ){
        if(dp[i][j]==dp[i][j-1]){
            j--;
        }else if(dp[i][j]==dp[i-1][j]){
            i--;
        }else{
            if(i>=1){
                if(ans==""){
                    ans = S[i];
                }else{
                    ans = S[i] + ans;
                }
            }else{
                if(ans==""){
                    ans = T[j];
                }else{
                    ans = T[j] + ans;
                }
            }
            
            i--;
            j--;
        }

    }

    if(dp[i][j]==0){
            cout << ans << endl;
            return 0;
    }else if(i==0){
        ans = S[0] + ans;
    }else if(j==0){
        ans = T[0] + ans;
    }

    cout << ans <<endl;
    return 0;

}

Measured memory_bytes: 70528
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}
 
const int N=3005;
int mod,phi;
namespace{
	int fac[N],rev[N],s[N][N];
	int power(int x,int p,int mo){
		int res=1;
		for(;p;p>>=1,x=(ll)x*x%mo)
			if(p&1)res=(ll)res*x%mo;
		return res;
	}
	int mul(int x,int y){
		return static_cast<ll>(x)*y%mod;
	}
	void add(int &x,int y){
		x=(x+y>=mod?x+y-mod:x+y);
	}
	int fix(int x){
		return x>=mod?x-mod:x;
	}
	int C(int n,int m){
		return m<0||m>n?0:mul(fac[n],mul(rev[m],rev[n-m]));
	}
	void init(){
		const int lim=3000;
		fac[0]=1;
		rep(i,1,lim)fac[i]=(ll)fac[i-1]*i%mod;
		rev[lim]=power(fac[lim],mod-2,mod);
		per(i,lim,1)rev[i-1]=(ll)rev[i]*i%mod;
		rep(i,0,lim)s[i][0]=1;
		rep(i,1,lim)rep(j,1,i)
			s[i][j]=fix(s[i-1][j-1]+mul(s[i-1][j],j+1));
	}
}
int n,ans;

int main(){
	read(n),read(mod),init();
	rep(i,0,n){
		int tot=power(2,power(2,n-i,mod-1),mod);
		int t=power(2,n-i,mod),coef=mul((i&1?mod-1:1),C(n,i));
		rep(j,0,i){
			add(ans,mul(coef,mul(tot,s[i][j])));
			tot=mul(tot,t);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 34304
#include<stdio.h>

int main(void){
  int n , c;
  scanf("%d %d",&n ,&c);

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

  int rist[31][100000] = {0};
  for(int i = 0;i < n;i ++){
    int x = s[i] , y = t[i] , z = a[i];

    for(int j = x;j <= y;j ++){
      rist[z][j] = 1;
    }
  }

  int count , ans = 0; 
  for(int i = 1;i <= 100000;i ++){
    count = 0;
    for(int j = 1;j <= 30;j ++){
      if(rist[j][i] == 1){
        count ++;
      }
    }
    if(count > ans){
      ans = count;
    }
  }

  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 15008
n=int(input())
s=input()
ans=0
for i in range(1000):
  t_str=str(i)
  t_len=len(t_str)
  t_str=(3-t_len)*"0"+t_str
  cur_idx=0
  ok=0
  for j,ss in enumerate(s):
    if ss==t_str[cur_idx]:
      cur_idx+=1
      ok+=1
    if cur_idx==3:break
  if cur_idx==3:
    ans+=1
print(ans) 



Measured memory_bytes: 42076
#include<iostream>

using namespace std;
const int N = 200010;

int a[N];

int main()
{
    int n;
	cin >> n;
	int x = 0;
    for(int i = 0; i < n; i++)	cin >> a[i], x ^= a[i];
    for(int i = 0; i < n; i++)	cout << (x ^ a[i]) << ' ';
    return 0;
}

Measured memory_bytes: 4308
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    uint64_t N;
    cin >> N;

    uint64_t ret = N;
    for(uint64_t i=1; i*i <=N; ++i) {
        if(N % i == 0) {
            uint64_t tmp1 = to_string(i).size();
            uint64_t tmp2 = to_string(N/i).size();
//            cout << tmp1 << " " << tmp2 << endl;
            ret = min(ret, max(tmp2,tmp1));
        }
    }
    cout << ret << endl;
    return 0;
}



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

int main(){
    ll N, K;
    cin >> N >> K;
    N=N-(N/K)*K;
    ll ans=1e19;
    ll pre[2]={-1, -1};
    int pre_num=0;
    while(true){
        N=abs(K-N);
        if(N <= ans) ans=N;
        if(pre[pre_num]==N) break;
        pre[pre_num]=N;
        pre_num=(pre_num+1)%2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632