akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    N = len(S)
    C = [0] * (N + 1)
    QL = [0] * (N + 1)
    A = [0] * (N + 1)
    QR = [0] * (N + 1)
    for i in range(N):
        if S[i] == 'A':
            A[i + 1] = A[i] + 1
        else:
            A[i + 1] = A[i]
        if S[i] == '?':
            QL[i + 1] = QL[i] + 1
        else:
            QL[i + 1] = QL[i]
    
    for i in range(N - 1,-1,-1):
        if S[i] == 'C':
            C[i] = C[i + 1] + 1
        else:
            C[i] = C[i + 1]
        if S[i] == '?':
            QR[i] = QR[i + 1] + 1
        else:
            QR[i] = QR[i + 1]
    
    power3 = [1]
    for i in range(N):
        power3.append(power3[-1]*3%MOD)

    ans = 0
    for i in range(N):
        if S[i] in 'AC':
            continue
        choose_A = (A[i]*power3[QL[i]] + (QL[i] > 0)*QL[i]*power3[QL[i] - 1])%MOD
        choose_B = (C[i + 1]*power3[QR[i + 1]] + (QR[i + 1] > 0)*QR[i + 1]*power3[QR[i + 1] - 1])%MOD
        ans += choose_A*choose_B%MOD
        ans %= MOD
    print(ans) 

if __name__ == '__main__':
    main()
    


Measured memory_bytes: 16708
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

vector<vector<int>>g;

int n,m;
vector<bool>seen;
void dfs (int v,int p) {
    seen[v] = true;
    for(auto nv : g[v]) {
        if(nv==p) continue;
        if(!seen[nv]) dfs(nv,v);
    }
}

int main() {
    cin >> n >>m;
    g.resize(n);
    seen.resize(n);
    rep(i,n) seen[i] = false;
    rep(i,m) {
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int ans = 0;
    rep(i,n) {
        if(seen[i]) continue;
        dfs(i,-1);
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13464
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define MODA 1000000007 

int main() {
    int ans = INF;
	int n, w, s[101], su=0;
	s[0] = 0;
	cin >> n;
	for(int i = 1; i<=n; i++){
		cin >> w;
		s[i] = s[i-1] + w;
		su += w;
	}
	for(int i = 1; i<n; i++){
		//cout << s[i];
		if(abs(s[i] - (su - s[i])) < ans) ans = abs(s[i] - (su - s[i]));
	}
	
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Point{
    ll x;
    ll y;
};
int main()
{
    int n;
    cin >> n;
    vector<Point> vp;
    for(int i=0; i<n; ++i){
        ll xi, yi;
        cin >> xi >> yi;
        vp.push_back({xi, yi});
    }
    sort(vp.begin(), vp.end(), [](Point &a, Point &b){return a.x + a.y < b.x + b.y;});
    ll d = abs(vp[0].x - vp[n-1].x) + abs(vp[0].y - vp[n-1].y);
    sort(vp.begin(), vp.end(), [](Point &a, Point &b){return a.x - a.y < b.x - b.y;});
    d = max(d, abs(vp[0].x - vp[n-1].x) + abs(vp[0].y - vp[n-1].y));
    cout << d;
    return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int m, n;
int b[501], r[501];

template<class T>
class Dinic {
private:

    struct edge {
        T to, cap, rev;
        edge(T to, T cap, T rev) :to(to), cap(cap), rev(rev) {}
    };

    T V;
    vector<vector<edge>> g;
    vector<T> level;      // sourceからの距離
    vector<T> itr;        // どこまで調べ終わったか

public:
    Dinic(T V) :V(V), g(V, vector<edge>()) {}

    void add_edge(T from, T to, T cap) {
        g[from].emplace_back(to, cap, g[to].size());
        g[to].emplace_back(from, 0, g[from].size()-1);
    }

    // sourceからの最短路を幅優先で探索
    void bfs(T s) {
        level = vector<T>(V, -1);
        queue<T> que;
        que.push(s);
        level[s] = 0;
        while (que.size()) {
            int v = que.front(); que.pop();
            for (edge &e : g[v]) {
                if (e.cap > 0 and level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    // v->tの増加路を探す
    T dfs(T v, T t, T f) {
        if (v == t) return f;
        for (T& i = itr[v]; i < g[v].size(); ++i) {
            edge& e = g[v][i];
            if (e.cap > 0 and level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    g[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    T max_flow(T s, T t) {
        T flow = 0, f;
        while (true) {
            bfs(s);
            if (level[t] < 0) return flow;
            itr = vector<T>(V, 0);
            while ((f = dfs(s, t, numeric_limits<T>::max())) > 0) {
                flow += f;
            }
        }
    }
};

int main() {
    while (cin >> m >> n, m, n) {
        int s = 0, t = 1;
        Dinic<int> flow(m+n+2);
        rep(i, m) {
            cin >> b[i];
            flow.add_edge(s, i+2, 1);
        }
        rep(i, n) {
            cin >> r[i];
            flow.add_edge(m+i+2, t, 1);
        }
        rep(i, m) rep(j, n) {
            if (__gcd(b[i], r[j]) != 1) {
                flow.add_edge(i+2, m+j+2, 1e8);
            }
        }
        cout << flow.max_flow(s, t) << endl;
    }
}



Measured memory_bytes: 7324
#include<iostream>
#include<cstdlib>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i(0);i<n;i++)
typedef long long ll;

int main(){
	int N;
    cin >> N;
    vector<int> A;
    rep(i,N){
        int a;
        cin >> a;
        A.push_back(a);
    }

    sort(A.begin(),A.end());
    string ans="YES";
    rep(i,N-1){
        if(A[i] == A[i+1]){
            ans = "NO";
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  set<ll> s;
  REP(i,n){
    ll a;
    cin >> a;
    if(s.find(a)!=s.end()){
      s.erase(a);
    }
    else{
      s.insert(a);
    }
  }
  cout << s.size() << endl;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;

void solve() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!i || s[i] != s[i - 1]) ans++;
	}
	cout << ans;
}
	

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}


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

using namespace std;
typedef long long ll;

int main() {
    int a, b;
    cin >> a >> b;
    int y = 0;
    while (y <= 1000) {
        y += 1;
        if ((int)(y*0.08) == a && (int)(y*0.1) == b) {
            cout << y << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  int d[n];
  for(int i=0;i<n;i++)cin >> d[i];
  sort(d, d+n, greater<int>());
  int mochi=1000, counter=0;
  for(int i=0;i<n;i++){
	if(mochi>d[i]){
      counter++;
      mochi=d[i];
      //cout << mochi <<endl;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int rez=123123213,n, x,p,s=0;
    cin>>n;
    int a[1001];
    for(int i=1; i<=n; ++i)
    cin>>a[i];
 for(int j=1; j<=111; ++j){
    p=j;
    s=0;
    for(int i=1; i<=n; ++i)
    {
        x=a[i];
        s+= (x-p) * (x-p);
    }
    rez = min(rez, s);
 }    
    cout<<rez;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std; 
int main() {
  short n, k, d, z, res = 0; 
  cin >> n >> k; 
  short tableau[101] = {0}; 
  for (short i = 0; i <k; i ++) {
     cin >> d; 
     for (int l = 0; l < d; l ++) {
       cin >> z; 
       tableau[z] ++; 
     }
  }
  for (short i = 1; i <= n; i ++) {
    if (tableau[i] == 0)
      res ++; 
  }
  cout << res; 
  return 0; 
  
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  
  typedef pair<int, int> Pii;

  int N;
  
  while(cin >> N && N) {
    
    vector<Pii> SCORE(N);
    
    for(int m=0; m<N; m++){
      
      cin >> SCORE[m].second;
      
      int all = 0;
      int strike[11] = {};
      
      for(int i=1; i<=10; i++){
        int sc; cin >> sc;
 
        if( strike[i-1] == 2 ) all += sc;
        if( i-2 >= 0 && strike[i-1] == 2 && strike[i-2] == 2 ) all += sc;
        if( strike[i-1] == 1 ) all += sc;
 
        if(sc == 10){
          all += sc;
          strike[i] = 2;
        }
        else {
          int add; cin >> add;
          if( strike[i-1] == 2 ) all += add;
          all += sc + add;
          if( sc + add == 10 ) strike[i] = 1;
        }
      }
       
      if( strike[10] == 2 ){
        int sc, add; cin >> sc >> add;
        all += sc + add;
        if( strike[9] == 2 ) all += sc;
      }
      else if( strike[10] == 1 ){
        int sc; cin>>sc;
        all += sc;
      }
      
      SCORE[m].first = -all;
      
    }
 
    sort(SCORE.begin(), SCORE.end());
    
    for(int i=0; i<N; i++){
      cout << SCORE[i].second << ' ' << -SCORE[i].first << endl;
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, MOD = 1e9 + 7;
int n;
int c[N];
ll dp[N], sum[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> c[i];
    dp[0] = 1;
    for(int i = 1; i <= n; i++) {
        if(c[i] == c[i - 1]) {
            dp[i] = dp[i - 1];
            continue ;
        }
        dp[i] = (dp[i - 1] + sum[c[i]]) % MOD;
        sum[c[i]] = dp[i];
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	ll n;
	cin >> n;
	ll a[n];
	REP(i,n) cin >> a[i];
	ll tmp[n + 1];
	tmp[0] = 0;
	REP(i,n){
		tmp[i + 1] = 2 * a[i] - tmp[i];
	}
	ll ans[n];
	ans[0] = tmp[n] / 2;
	REP(i,n){
		cout << ans[i] << " ";
		ans[i + 1] = 2 * a[i] - ans[i];
	}
}

Measured memory_bytes: 3712
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>

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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> edges(N);
    vector<pair<int, int>> E;

    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        edges[a - 1].emplace_back(b - 1);
        edges[b - 1].emplace_back(a - 1);
        E.emplace_back(make_pair(a - 1, b - 1));
    }

    int used[100000] = {};
    int color[100000] = {};
    map<pair<int, int>, int> mc;
    int ans = 0;

    queue<int> que;
    que.emplace(0);
    used[0] = 1;
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        int col = 1;
        for (int c : edges[v]) {
            if (used[c] == 1) continue;
            if (col == color[v]) col++;
            color[c] = col;
            mc[make_pair(v, c)] = col;
            mc[make_pair(c, v)] = col;
            ans = max(ans, col);
            col++;
            que.emplace(c);
        }
        used[v] = 1;
    }

    cout << ans << endl;
    REP(i, N - 1) {
        cout << mc[E[i]] << endl;
    }

    return 0;
}

Measured memory_bytes: 20084
#include "iostream"
#include "vector"
#include "algorithm"
#include "math.h"

using namespace std;
typedef long long ll;

int main()
{
  int h, w;
  cin >> h >> w;
  char a[60][60];
  for (int i = 1; i <= h; i++)
  {
    for (int j = 1; j <= w; j++)
    {
      cin >> a[i][j];
    }
  }
  int ans[60][60];
  for (int i = 1; i <= h; i++)
  {
    for (int j = 1; j <= w; j++)
    {
      ans[i][j] = 0;
    }
  }

  for (int i = 1; i <= h; i++)
  {
    for (int j = 1; j <= w; j++)
    {
      if (a[i][j] == '#')
      {
        for (int k = -1; k < 2; k++)
        {
          for (int l = -1; l < 2; l++)
          {
            ans[i + k][j + l]++;
          }
        }
      }
    }
  }
  for (int i = 1; i <= h; i++)
  {
    for (int j = 1; j <= w; j++)
    {
      if (a[i][j] == '#')
      {
        cout << '#';
      }
      else
      {
        cout << ans[i][j];
      }
    }
    cout << "\n";
  }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 * Gluttony
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            long K = sc.nextLong();

            long[] A = new long[N];
            long[] F = new long[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextLong();
            }
            for (int i = 0; i < N; i++) {
                F[i] = sc.nextLong();
            }

            long sum = Arrays.stream(A).parallel().sum();
            if (sum <= K) {
                System.out.println(0);
                return;
            }

            Arrays.sort(A);
            Arrays.sort(F);

            long min = 0;
            long max = 0;
            for (int i = 0; i < N; i++) {
                max = Math.max(max, A[i] * F[N - 1 - i]);
            }

            while (max - min > 1) {
                long mid = (min + max) / 2;

                long need = 0;
                for (int i = 0; i < N; i++) {
                    need += Math.max(0, A[i] - mid / F[N - 1 - i]);
                }

                if (need > K) {
                    min = mid;
                } else {
                    max = mid;
                }
            }

            System.out.println(max);
        }

    }

}


Measured memory_bytes: 107032
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int m = fs.nextInt();
		int mountain[] = new int[n + 1];
		int h[] = new int[n + 1];
		for (int i = 1; i < n + 1; i++) {
			h[i] = fs.nextInt();
		}
		for (int i = 0; i < m; i++) {
			int a = fs.nextInt();
			int b = fs.nextInt();
			if (h[a] > h[b]) {
				mountain[b]++;
			} else if (h[a] < h[b]) {
				mountain[a]++;
			} else {
				mountain[a]++;
				mountain[b]++;
			}
		}
		int count = 0;
		for (int i = 1; i < n + 1; i++) {
			if (mountain[i] == 0)
				count++;
		}
		System.out.println(count);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 36224
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int n;
	cin >> n;
	cout << (1000 - n % 1000) % 1000 << '\n';
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	int N; cin >> N;
	vector<int> A_u(N), A_d(N);
	rep(i, 0, N)cin >> A_u[i];
	rep(i, 0, N)cin >> A_d[i];

	vector<int> U(N), D(N);
	U[0] = A_u[0];
	rep(i, 1, N)U[i] = U[i - 1] + A_u[i];
	D[N - 1] = A_d[N - 1];
	for (int i = N - 2; i >= 0; i--)D[i] = D[i + 1] + A_d[i];

	int ans = 0;
	rep(i, 0, N)ans = max(ans, U[i] + D[i]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] array = new int[n];
        Arrays.fill(array, -1);
        
        while (m-- > 0) {
            int digit = sc.nextInt() - 1;
            int num = sc.nextInt();
            
            if (digit == 0 && num == 0) {
                if (n != 1) {
                System.out.println(-1);
                return;
                } else {
                    array[digit] = -1;
                    continue;
                    
                }
            }
            
            if (array[digit] == -1 || array[digit] == num) {
                array[digit] = num;
            } else {
                System.out.println(-1);
                return;
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (n == 1 && array[0] == -1) {
                System.out.println(0);
                return;
            }
            if (array[i] == -1) {
                array[i] = 0;
            }
            if (i == 0 && array[i] == 0) array[i]++;
            System.out.print(array[i]);
        }
        System.out.println();
        
    }
}


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

using namespace std;
#define fast	ios::sync_with_stdio(0);cin.tie(0);
#define ll 		long long int
#define INF     1e18L
#define precision(x)	fixed << setprecision(x)
const ll mod = 1e9 + 7;

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


ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}
const int N = 2e5 + 5;
const int M = 2005;

//--------------------------------------------------------------------------------------------------------------------------//
int vis[N];
vector<int> g[N];

void dfs(int v) {
	if (vis[v]) return;
	vis[v] = 1;
	for (auto u : g[v]) {
		dfs(u);
	}
}
void solve() {
	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int ans = -1;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			++ans;
			dfs(i);
		}
	}
	cout << ans << endl;
}

int main() {
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int tc = 1;
	// cin >> tc;

	int _ = 0;
	while (_++ < tc) {
		solve();
	}

	return 0;
}






Measured memory_bytes: 12344
open Batteries

let () =
  let n = Scanf.scanf "%d " (fun a -> a) in

  let rec f res n b =
    if n = 0 then res
    else f (res + (n mod b)) (n / b) b
  in

  let rec loop i ans =
    if i < n then (
      let i9 = i in
      let tmp1 = (n - (9 * i9)) in
      let i6 = tmp1 / 6 in
      let i1 = tmp1 mod 6 in
      let ans_c = (f 0 i9 9) + (f 0 i6 6) + i1 in
      if tmp1 >= 0 then
        loop (i+1) (if ans < ans_c then ans else ans_c)
      else
        ans

    ) else (
      ans
    )
  in
  Printf.printf "%d\n" (loop 0 100000);



Measured memory_bytes: 1152
i=gets.chomp.to_i
i.times do
 a,b,c=gets.chomp.split
 a,b,c=a.to_i,b.to_i,c.to_i
 if a**2==b**2+c**2||b**2==a**2+c**2||c**2==a**2+b**2
  puts 'YES'
 else
  puts 'NO'
 end
end

Measured memory_bytes: 6112
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

int main(){
	string S,T;
	cin >> S >> T;
	int count=0;

	for (int i = 0; i < 3; i++){
		if(S[i] == T[i]){
			count++;
		}
	}
	cout << count << endl;

	return 0;
}

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

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)

#define endl '\n'
const int N = 1e5 + 10;
const int K = 1e3 + 10;

int x[N], y[N], col[N], sat[N];

int ry[K][2];
vector<int> crx[K];

int main() {
  fast_io;
  int n, k;
  cin >> n >> k;
  int twok = 2 * k;
  int sat_now = 0;
  for (int i = 0; i < n; i++) {
    string co;
    cin >> x[i] >> y[i] >> co;
    if (co == "W")
      col[i] = 1;
    else
      col[i] = 0;
    int ccol = 1;
    if (x[i] % twok >= k)
      ccol ^= 1;
    if (y[i] % twok >= k)
      ccol ^= 1;
    if (ccol == col[i])
      sat[i] = 1;
    ry[y[i] % k][sat[i]]++;
    crx[x[i] % k].PB(i);
    sat_now += sat[i];
  }
  // trace(sat_now);
  int max_sat = sat_now;
  for (int sx = 0; sx < twok - 1; sx++) {
    int sat_now_b = sat_now;
    for (int sy = 0; sy < k - 1; sy++) {
      int cy = (sy) % k;
      sat_now += ry[cy][0] - ry[cy][1];
      // trace(sx, sy, sat_now);
      max_sat = max(max_sat, sat_now);
    }
    sat_now = sat_now_b;
    int cx = (sx) % k;
    for (auto v : crx[cx]) {
      sat_now -= sat[v];
      ry[y[v] % k][sat[v]]--, sat[v] ^= 1, ry[y[v] % k][sat[v]]++;
      sat_now += sat[v];
    }
    max_sat = max(max_sat, sat_now);
  }
  cout << max_sat << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int>p(n);
	vector<int>q(n);
	rep(i, n)cin >> p[i];
	rep(i, n)cin >> q[i];
	
	int where_p = 1;
	int where_q = 1;
	bool check_p, check_q;
	int cnt = 1;
	vector<int>x(n);
	iota(x.begin(), x.end(), 1);
	
	while (next_permutation(x.begin(),x.end())) {
		check_p = true;
		check_q = true;
		rep(i, n) {
			if (!(x[i] == p[i])) {
				check_p = false;
			}
			if (!(x[i] == q[i])) {
				check_q = false;
			}
			if (!check_p && !check_q)break;
		}
		cnt++;
		if (check_p)where_p = cnt;
		if (check_q)where_q = cnt;
	}
	
	int ans = where_p - where_q;
	if (ans < 0)ans *= -1;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <set>
#include <algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  int count[26] = {};
  for(auto ch : s){
	count[ch - 'a']++;
  }
  for(int i = 0; 26 > i; i++){
	if(count[i] > (s.length() + 2) /3){
     cout << "NO" <<endl; 
      return 0;
    }
  }
    cout << "YES" << endl;
 	return 0;
}

Measured memory_bytes: 512
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
A = list(map(int,(input().split())))

ans = 0
r = 0
sum = 0
xor = 0
for l in range(N):
    while r < N and sum+A[r] == xor^A[r]:
        sum += A[r]
        xor ^= A[r]
        r += 1
    sum -= A[l]
    xor ^= A[l]
    ans += r-l

print(ans)

Measured memory_bytes: 72560
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s,ans="Yes"; cin>>s;
  int n=s.length();
  if(n==1) ans="No";
  char a[n];
  for(int i=0;i<n;i++) a[i]=s[i];
  sort(a,a+n);
  int count=1;
  for(int i=0;i<n-1;i++){
	if(a[i]==a[i+1]) count++;
    else{
      if(count%2==1) ans="No";
      count=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
 
int Point[N+1];
int Matrix[N+1][N+1];
int n;
 
void MatrixChange(void){
 int i,j,k,l;
 for(i = 1;i <= n;i++){
    Matrix[i][i] = 0;
  }
  for(k = 2;k <= n;k++){
    for(i = 1;i <= n-k+1;i++){
      j = i + k -1;
      Matrix[i][j] = 1000000000;
      for(l = i;l <= j-1;l++){
    if(Matrix[i][j] > Matrix[i][l]+Matrix[l+1][j]+Point[i-1]*Point[l]*Point[j]){
      Matrix[i][j] =  Matrix[i][l]+Matrix[l+1][j]+Point[i-1]*Point[l]*Point[j];
    }
    else{
      Matrix[i][j] = Matrix[i][j];
    }
      }
    }
  }
}
int main(){
 
  int i;
   
  scanf("%d",&n);
 
  for(i = 1;i <= n;i++){
    scanf("%d%d",&Point[i-1],&Point[i]);
  }
  MatrixChange();
 
  printf("%d\n",Matrix[1][n]);
     
    return 0;
}

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

long long mod = 1e9 + 7, dp[100002];
long long N, M;
bool broken[100001];

int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a;
        cin >> a;
        broken[a] = true;
    }
    dp[0] = 1;
    if(!broken[1]){
        dp[1] = 1;
    }
    for(int i = 2; i <= N; i++){
        if(!broken[i]){
            dp[i] = dp[i - 1] + dp[i - 2];
            dp[i] %= mod;
        }
    }
    cout << dp[N] << endl;
}


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

int main() {
    int N, A, B, C, ans = mod;
    cin >> N >> A >> B >> C;
    vector<int> l(N);
    for(int i = 0; i < N; ++i)
        cin >> l[i];
    for(int i = 0; i < (1 << (N * 2)); ++i) {
        int asum = 0, bsum = 0, csum = 0, mpt = 0;
        for(int j = 0; j < N * 2; j += 2) {
            int flag = 0;
            if(i & (1 << j))
                flag++;
            if(i & (1 << (j + 1)))
                flag += 2;
            switch(flag) {
            case 1:
                if(asum != 0)
                    mpt += 10;
                asum += l[j / 2];
                break;
            case 2:
                if(bsum != 0)
                    mpt += 10;
                bsum += l[j / 2];
                break;
            case 3:
                if(csum != 0)
                    mpt += 10;
                csum += l[j / 2];
                break;
            }
        }
        if(asum == 0 || bsum == 0 || csum == 0)
            continue;
        mpt += abs(A - asum) + abs(B - bsum) + abs(C - csum);
        ans = min(ans, mpt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  string A, B;
  cin>>A>>B;

  if(A.size() > B.size()){
    cout<<"GREATER"<<endl;
    return 0;
  }else {
    if(A.size() == B.size()){
      REP(i,0,A.size()){
        if(A[i] > B[i]){
          cout<<"GREATER"<<endl;
          return 0;
        }
        if(A[i] < B[i]){
          cout<<"LESS"<<endl;
          return 0;
        }
      }
      cout<<"EQUAL"<<endl;
    }else{
      cout<<"LESS"<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <cstring>
#include <stdlib.h>
#include <string.h>
#include <cmath>
using namespace std;

int main(void){
    int x;
    cin >> x;
    if(x >= 30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#include <string>
#define ll long long
using namespace std;

int main()
{
	string s1,s2,s3;
	
	int i,a=0,n;
	cin>>n;
	
	cin>>s1;
	cin>>s2;
	
	for(i=0;i<n;i++)
	{
		s3+=s1[i];
		s3+=s2[i];
		
		
	}
	
	cout<<s3;
	
	
}
	


	
	
	
   



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

def main():
    a,b,c=map(int,input().split())
    s=(c-a-b)**2-4*a*b
    if s>0 and a+b<c:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
// #include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }



void solve(void)
{ 
  int N,M; cin>>N; cin>>M;  
  priority_queue<int> q;
  for (int i = 0; i < N; i++)
  {
    int X;cin>>X;
    q.push(X);
  }
  for (int i = 0; i < M; i++)
  {
    int X = q.top();
    q.pop();
    q.push(X/2);
  }
  int res = 0;
  while(!q.empty())
  {
    res += q.top();
    q.pop();
  }
  cout<<res<<endl;

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

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 4260
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::*;
use std::collections::*;
use std::ops::*;
use procon::*;

pub fn main() -> () {
    let N = read_line().parse::<i32>().unwrap();
    println!("{}", N / 3);
    return;
}

pub mod procon {
    use std;
    use std::io;
    use std::str::FromStr;

    pub fn read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim_right().to_owned()
    }

    pub fn read_words<T>() -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace()
            .map(|word| T::from_str(word).unwrap())
            .collect()
    }

    pub fn read_vec<T>(len: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut vec = Vec::new();
        while vec.len() < len {
            let words = read_words();
            for word in words {
                vec.push(word);
            }
        }
        vec
    }

    pub fn make_vec<T, F>(len: usize, f: F) -> Vec<T>
    where
        F: Fn(usize) -> T,
    {
        return (0..len).into_iter().map(f).collect();
    }
}


Measured memory_bytes: 4352
P=10**9+7
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,P)[0]
N=int(input())
Fact=[0 for i in range(N+1)]
Finv=[0 for i in range(N+1)]
Fact[0]=1
Finv[0]=1
for i in range(N):
    Fact[i+1]=((i+1)*Fact[i])%P
    Finv[i+1]=(Finv[i]*inv(i+1))%P
SGN=[0 for i in range(N)]
ans=0
for k in range(N):
    if 2*k-N>=0:
        SGN[k]=(((Fact[k-1]*Fact[k])%P)*Finv[2*k-N])%P
        ans=(ans+k*(SGN[k]-SGN[k-1]))%P
print(ans)


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

int main(){
  int a,b,c,d,n;
  int ans=0;
  while(scanf("%d",&n) != EOF){
    ans = 0;
    for(a = 0;a < 10;a++){
      for(b = 0;b < 10;b++){
	for(c = 0;c < 10;c++){
	  for(d = 0;d < 10;d++){
	    if(a+b+c+d == n)ans++;
	  }
	}
      }
    }
    cout<<ans<<endl;
  }
    return 0;
}

Measured memory_bytes: 1204
require "set"

n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i).each.with_index(1).sort.reverse.to_h{|x, i| [i, x]}
delete = Set.new
m.times do
  a,b = gets.split.map(&:to_i)
  if h[a] == h[b]
    delete << a
    delete << b
  elsif h[a] > h[b]
    delete << b
  else
    delete << a
  end
end

puts (n - delete.count)

Measured memory_bytes: 31336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main()
{
    ll n, x;
    cin >> n >> x;
    vector<ll> d(n);
    for(int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        d[i] = abs(a-x);
    }
    ll g = gcd(d[0], d[1]);
    for(int i = 2; i < n; i++)
    {
        g = gcd(g, d[i]);
    }
    cout << g << endl;
}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int x=100*a+10*b+c;
  if(x%4==0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;

using namespace std;


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

    ll m=sqrt((double)n);
    if((m+1)*(m+1)==n) m++;

    vector<ll> a;
    int i;
    for(i=1; i<=m; i++) {
        if(n%i==0) {
            a.push_back(i);
            if(n/i>i) a.push_back(n/i);
        }
    }

    ll sum=0;
    for(i=0; i<(int)a.size(); i++) {
        if(a[i]>2) {
            ll m=a[i]-1;
            if(n/m==n%m) sum+=m;
        }
    }

    printf("%lld\n", sum);

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

template <int N> class Trie{
public:
  int table[N];
  
  struct node{
    int val;
    node *ch[N] = {};
    
    node(int val): val(val){}
    node(): val(0){}
  };

  Trie(const string &s){
    REP(i,(int)s.size()){
      table[(int)s[i]] = i;
    }
  }

  node *root = nullptr;

  node* insert(node *t, const string &s, int val, int i){
    if(!t) t = new node();

    if(i >= (int)s.size()){
      t->val = val;
      return t;
    }

    int c = table[(int)s[i]];
    t->ch[c] = insert(t->ch[c], s, val, i+1);

    return t;
  }
  
  void insert(const string &s, int val){
    root = insert(root, s, val, 0);
  }

  node* find(node *t, char c){
    if(!t) return t;
    return t->ch[table[(int)c]];
  }

  node* find(const string &s){
    node *t = root;
    int i = 0;
    
    while(t and i<(int)s.size()){
      t = find(t,s[i]);
      if(!t) return nullptr;
      ++i;
    }
 
    return t;
  }
};


LLI dfs(Trie<2>::node *t, LLI d){
  LLI ret = 0;

  if(!t->val){
    REP(i,2){
      if(t->ch[i]){
        ret ^= dfs(t->ch[i],d-1);
      }else{
        LLI x = 1;

        while(d%(x*2)==0){
          x *= 2;
        }

        ret ^= x;
      }
    }
  }
  
  return ret;
}



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

  LLI N,L;
  while(cin >> N >> L){
    Trie<2> trie("01");

    REP(i,N){
      string s; cin >> s;
      trie.insert(s,1);
    }

    LLI ans = dfs(trie.root,L);

    cout << (ans ? "Alice" : "Bob") << endl;
  }
  
  return 0;
}


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

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 int n;
 cin >> n;
 vector <long long int> a(n), p(n), s(n);
 for (int i = 0; i < n; ++i){
	cin >> a[i];
 }
p[0] = a[0];
s[n-1] = a[n-1];
 for (int i = 1; i < n; ++i){
p[i] = gcd(p[i-1],a[i]);
s[n - 1 - i] = gcd(s[n - i],a[n-1-i]);
 }
long long int m = s[1]; //first element removed
 for (int i = 1; i < n-1; ++i){ //remove second element to second last element
	 m = max(gcd(p[i-1],s[i+1]), m);
 }
 m = max(m, p[n-2]); //remove last element
cout << m << "\n";
return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define inf1 INT_MAX
#define inf2 LLONG_MAX
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sbit __builtin_popcount
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define rit(it,x) for(auto it=x.begin();it!=x.end();it++)
#define cases(t) int t; cin>>t; rep(casn,1,t+1)
#define fill(a,b) memset(a,b,sizeof(a))
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define infile ifstream fin; fin.open("input.txt")
#define outfile ofstream fout; fout.open("output.txt")
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<ll,int>
#define pll pair<ll,ll>
#define p_queue priority_queue< plii,vector< plii >,greater< plii > > 
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define sl(x) scanf("%lld",&x)
#define sst(x) scanf("%s",x)
#define pl(x) printf("%lld\n",x)
#define pi(x) printf("%d\n",x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
vector<string> str;
ll dp[1005][1005];
int n,m;

inline ll binex(ll a,ll b)
{
    ll ans=1,temp=a%mod;
    while(b!=0){
        if(b&1) ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b=b>>1;
    }
    return ans;
}

inline bool ok(int x,int y)
{
    return (x>=0 && x<n && y>=0 && y<m);
}

inline ll solve(int x,int y)
{
    if(x==n-1 && y==m-1) return dp[x][y]=1;
    if(dp[x][y]!=-1) return dp[x][y];
    int res=0;
    if(ok(x+1,y) && str[x+1][y]!='#') res+=solve(x+1,y);
    if(ok(x,y+1) && str[x][y+1]!='#') res+=solve(x,y+1);
    return dp[x][y]=res%mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    rep(i,0,n){
        string s; cin>>s;
        str.pb(s);
    }
    fill(dp,-1);
    cout<<solve(0,0)<<endl;
}

Measured memory_bytes: 9344
# backfront
N = int(input())
a = []
for _ in range(N):
    x = int(input())
    a.append((_, x))
a.sort(key=lambda x: x[1])
a.append((-10000000000000000, 10**20))
cnt, now, maxi = 0, -1, 0
for p, v in a:
    if now < p:
        cnt += 1
        now = p
    elif now > p:
        maxi = max(maxi, cnt)
        cnt = 1
        now = p
print(N-maxi)

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

mod = 10**9 + 7
K = int(input())
S = input().rstrip()

N = K + len(S)
fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for i in range(1, N+1):
    fact[i] = i * fact[i-1] % mod
fact_inv[N] = pow(fact[N], mod-2, mod)
for i in range(1, N+1)[::-1]:
    fact_inv[i-1] = i * fact_inv[i] % mod
comb = lambda n, k: fact[n] * fact_inv[k] * fact_inv[n-k] % mod

ans = 0
for i in range(K+1):
    ans = (ans + comb(K - i + len(S) - 1, len(S) - 1) * pow(25, K - i, mod) * pow(26, i, mod)) % mod
print(ans)

Measured memory_bytes: 117284
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
double t,x;
cin>>t>>x;
cout<<t/x;
cout.precision(10);


    return 0;
  }


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>
#include <cassert>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    int ans = INF;
    for (int i = 0; i < h; i++) cin >> s[i];
    for (int div = 0; div < (1 << (h - 1)); div++) {
        int g = 0;  //total group num
        vector<int> id(h);  // i'th row's group num
        for (int i = 0; i < h; i++) {
            id[i] = g;
            if ((div >> i) & 1) g++;
        }
        g++;

        vector<vector<int> > c(g, vector<int>(w));
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                c[id[i]][j] += (s[i][j] - '0');

        int num  = g - 1;
        vector<int> now(g);
        for (int j = 0; j < w; j++) {
            bool ok1 = true;
            for (int i = 0; i < g; i++) now[i] += c[i][j];
            for (int i = 0; i < g; i++)
                if (now[i] > k) ok1 = false;
            if (!ok1) {
                num++;
                now = vector<int>(g);
                bool ok2 = true;
                for (int i = 0; i < g; i++) now[i] += c[i][j];
                for (int i = 0; i < g; i++)
                    if (now[i] > k) ok2 =  false;
                if (!ok2) {
                    num = INF;
                    break;
                }
            }
        }
        ans = min(ans, num);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import collections
n=int(input()) 
a=list(map(int, input().split())) 
q=int(input()) 
b = []
c = []

for i in range(q):
    B,C=map(int, input().split())
    b.append(B)
    c.append(C)

ans = sum(a)
cc = collections.Counter(a)
#print(cc)

for i in range(q):
    tmp = cc[b[i]]
    d = c[i] - b[i] 
    cc[b[i]] = 0
    cc[c[i]] += tmp
    ans = ans + d * tmp
    #print(cc)
    print(ans)

Measured memory_bytes: 30228