akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		HashSet<Integer> s = new HashSet<Integer>();
		for(int i=0; i<K; i++) {
			s.add(sc.nextInt());
		}
		while(!ok(N, s)) {
			N++;
		}
		System.out.println(N);
	}
	
	static boolean ok(int N, HashSet<Integer> s) {
		while(N != 0) {
			if(s.contains(N%10)) return false;
			N /= 10;
		}
		return true;
	}
	
	// print
	static void print(String s) {
		System.out.println(s);
	}
	
	// union find lib
	// usage:
	// 最初にinitを呼ぶ
	// root: 直接は呼ばないで
	// unite: まとめる
	// same: グループ判定
	static void init(int par[], int N) {
		for(int i=0; i<N; i++) {
			par[i] = i;
		}
	}
	
	static int root(int x, int [] par) {
		if(par[x] == x) {
			return x;
		} else {
			return (par[x] = root(par[x], par));
		}
	}
	
	static boolean same(int x, int y, int[] par) {
		return root(x, par) == root(y, par);
	}
	
	static void unite(int x, int y, int[] par) {
		x = root(x, par);
		y = root(y, par);
		if(x == y) return;
		par[x] = y;
	}
	
	// end union find lib
	
	// number lib
	
	static long lcm(long a, long b) {
		return a*(b/gcd(a, b));
	}
	
	static long gcd(long a, long b) {
		long ta = Math.max(a, b);
		long tb = Math.min(a, b);
		long tmp;
		while((tmp = ta%tb) != 0) {
			ta = tb;
			tb = tmp;
		}
		return tb;
	}
	
	static long modcomb(long n, long k, long mod) {
		if(k==1) {
			return n;
		}
		
		long ans = 1;
		for(long i=n; i>=n-k+1; i--) {
			ans = (ans * i)%mod;
		}
		for(long i=k; 0<i; i--) {
			ans = (ans * modpow(i, mod-2, mod)) % mod;
		}
		return ans;
	}
	
	static long modpow(long a, long b, long mod) {
		if(b==0) return 1;
		if(b%2==0) {
			long d = modpow(a, b/2, mod);
			return (d*d)%mod;
		} else {
			return (a*modpow(a, b-1, mod))%mod;
		}
	}
	
	static int disit(long a, long d) {
		int count = 0;
		while(a!=0) {
			a = a/d;
			count++;
		}
		return count;
	}
	
	// end number lib
}

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

int main(void) {
	int a, b,tmp;
	while (1) {
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		if (b < a) {
			tmp = b;
			b = a;
			a = tmp;
		}
		cout << a << " " << b << endl;
	}
		
	return 0;
}


Measured memory_bytes: 3028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define lPair pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int H,W;
char a[1010][1010];
int dist[1010][1010];
void init(){
    for(int i = 0; i <=1000; i++){
        for(int j = 0; j <= 1000; j++){
            dist[i][j] = 0;
        }
    }
}
void dfs(){
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            dist[i][j] %= MOD;
            if(a[i+1][j] == '.') dist[i+1][j] += dist[i][j];
            if(a[i][j+1] == '.') dist[i][j+1] += dist[i][j];
        }
    }
}
int main(){
    init();
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }
    dist[0][0] = 1;
    dfs();
    dist[H-1][W-1] %= MOD;
    cout << dist[H-1][W-1] << endl;
}



Measured memory_bytes: 5248
import sys
for line in sys.stdin:
    a,b,c,d,e,f = map(float, line.split())
    x = round((c*e-b*f)/(a*e-b*d), 3)
    y = round((a*f-c*d)/(a*e-b*d), 3)
    if x == -0:
        x = 0
    if y == -0:
        y = 0
    print("{0:.3f}".format(x), "{0:.3f}".format(y))

Measured memory_bytes: 7436
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()

double calc_dist(double x1, double y1, double x2, double y2){
    const double dx = x1 - x2;
    const double dy = y1 - y2;
    return sqrt(dx * dx + dy * dy);
}

int main(){
    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    double t1 = ((double)h / 12 + (double)m / 60 / 12) * 2 * M_PI;
    double t2 = (double)m / 60 * 2 * M_PI;

    double x1 = (double)a * cos(t1);
    double y1 = (double)a * sin(t1);
    double x2 = (double)b * cos(t2);
    double y2 = (double)b * sin(t2);
    double d = calc_dist(x1, y1, x2, y2);
    printf("%.10f\n", d);
    return 0;
}


Measured memory_bytes: 4032
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int mod = (int)1e9+7;


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; cin >>n;
	VI a(100100);
	rep(i, n){
		int za;  cin>>za;
		a[i]=za;
	}
	
	ll ans=0;
	rep(i,100000){
		if(a[i]>1) ans += a[i]/2;
		a[i] %=2;
		if(a[i] && a[i+1]>0){ ans++; a[i+1]--;}
	}
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>

int main()
{
    long long n, a, b;
    while(scanf("%lld%lld%lld", &n, &a, &b) != EOF)
    {

        if(a == b && n == 1)
            printf("1\n");
        else if(b < a || n == 1)
            printf("0\n");
        else if(n == 2)
            printf("1\n");
        else
        {
            long long ans = (b - a) * (n - 2) + 1;
            printf("%lld\n", ans);
        }

    }
    return 0;
}

Measured memory_bytes: 128
import java.math.BigDecimal;
import java.util.Scanner;
class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];

        for(int i=0;i<N;i++)a[i] = sc.nextInt();
        int max=a[0];
        BigDecimal ans =new BigDecimal(0);
        for(int i=1;i<N;i++){
            if(max>a[i]){
                ans = ans.add(BigDecimal.valueOf(max - a[i]));
            }else{
                max = a[i];
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 60268
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n==0 && r==0){
                break;
            }

            int[] yama = new int[n];
            for(int i=0;i<n;i++){
                yama[i] = n-i;
            }

            for(int i=0;i<r;i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                int[] new_yama = new int[n];
                for(int j=0;j<c;j++){
                    new_yama[j] = yama[p-1+j]; 
                }

                for(int j=c;j<c+p-1;j++){
                    new_yama[j] = yama[j-c]; 
                }

                for(int j=p-1+c;j<n;j++){
                    new_yama[j] = yama[j];
                }
                yama = new_yama;
            }
            System.out.println(yama[0]);
        }
    }
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

struct data {
	llong place;
	llong many;
	llong gas;

	data(){};
	data(llong p, llong m, llong g) :
		place(p),
		many(m),
		gas(g)
	{};

	bool operator<(const data &ri) const {
		return many == ri.many ?
			gas > ri.gas :
			many < ri.many;
	}
	bool operator>(const data &ri) const {
		return many == ri.many ?
			gas < ri.gas :
			many > ri.many;
	}
};

llong N, M, L, Q;
vector<vector<lpair>> edges;
vector<lpair> query;

vector<llong> solve(int start) {
	vector<data> dis(N+1, data(inf, inf, -inf));
	dis[start] = data(start, 0, L);

	vector<llong> ret(N+1, inf);

	priority_queue<data, vector<data>, greater<data>> que;
	que.push(data(start, 0, L));
	while (que.size()) {
		data now = que.top();
		que.pop();
		if (dis[now.place] < now) continue;
		ret[now.place] = min(ret[now.place], now.many);
		for (auto edge: edges[now.place]) {
			if (now.gas >= edge.second) {
				data next(edge.first, now.many, now.gas - edge.second);
				if (dis[next.place] > next) {
					dis[next.place] = next;
					que.push(next);
				}
			}
			data next(edge.first, now.many + 1, L - edge.second);
			if (dis[next.place] > next) {
				dis[next.place] = next;
				que.push(next);
			}
		}
	}

	return ret;
}

int main() {
	cin >> N >> M >> L;

	edges.resize(N+1);
	llong a, b, c;
	for (int i = 0; i < M; ++i) {
		cin >> a >> b >> c;
		if (c > L) continue;
		edges[a].push_back(lpair(b, c));
		edges[b].push_back(lpair(a, c));
	}

	cin >> Q;
	query.resize(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> query[i].first >> query[i].second;
	}

	vector<vector<llong>> ans(N+1);
	for (int i = 1; i <= N; ++i) {
		ans[i] = solve(i);
	}

	for (auto q : query) {
		cout << (ans[q.first][q.second] == inf ? -1 : ans[q.first][q.second]) << endl;
	}

	return 0;
}


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

int main () {
    string w, t;
    int cnt = 0;
    cin >> w;
    while(true) {
        cin >> t;
        string at;
        if (t == "END_OF_TEXT") break;
        for (int i = 0; i < t.length(); i++) {
            if (t[i] >= 'A' && t[i] <= 'Z') {
                t[i] = t[i] + ('a' - 'A');
            }
            at += t[i];
        }
        if (at == w) {
            cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3144
h, w, k = map(int, input().split())
s = [list(map(int, list(input()))) for _ in range(h)]
result = []
if h*w<=k:
    result.append(0)
else:
    for i in range(2**(h-1)):
        checker, num = 0, i
        while num > 0:
            checker += num%2
            num >>= 1
        x = 0
        c = [0 for _ in range(checker+1)]

        for j in range(w):
            num = i
            p = 0
            nex = [0 for _ in range(checker+1)]
            for m in range(h):
                nex[p] += s[m][j]
                p += num%2
                num = num >> 1          
            if any(nex[m]>k for m in range(checker+1)):
                x = float('inf')
                break

            if all(nex[m]+c[m] <= k for m in range(checker+1)):
                c = [c[I]+nex[I] for I in range(checker+1)]
            else:
                x += 1
                c = nex
        result.append(checker+x)
print(min(result))

Measured memory_bytes: 54104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  n--; k--;
  int ans = (n+k-1)/k;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=7+1e9;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
ll qpow(ll a,ll b,ll p){a%=p; ll ret=1;for(;b;b>>=1,a=a*a%p) if(b&1) ret=ret*a%p; return ret;}
ll getInv(ll x,ll p){return qpow(x,p-2,p);}
const int N=5+1e5;
vector<int> G[N];
int n,m;
bool vis[N];
int pa[N];
void bfs(int st){
    queue<int> q;
    vis[st]=1;
    q.push(st);
    while(q.size()){
        int x=q.front();
        //printf("->%d",x);
        vis[x]=1;
        q.pop();
        for(auto v:G[x])
            if(!vis[v]){
                pa[v]=x;
                vis[v]=1;
                q.push(v);
            }
    }
}
int main(){
    scanf("%d%d",&n,&m);
    memset(vis,0,(n+1)*sizeof(bool));

    for(int i=1;i<=m;i++){
        int u,v; scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }    
    bfs(1);
    bool ok=1;
    for(int i=1;i<=n;i++) if(!vis[i]) ok=0;
    if(!ok) puts("No");
    else{
        puts("Yes");
        for(int i=2;i<=n;i++) printf("%d\n",pa[i]);
    }
}

Measured memory_bytes: 10668
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    string T;
    cin >> T;
    rep(i, T.size()){
        if(T[i] == '?'){
            T[i] = 'D';
        }
    }
    cout << T;
}

Measured memory_bytes: 3752
vec = []

loop do
  n, m = gets.split.map(&:to_i)
  break if n.zero? && m.zero?

  as = gets.split.map(&:to_i)
  max = 0
  pq = []

  as.each do |a|
    cq = pq.dup
    until cq.empty?
      current_sum = a + cq.pop
      if current_sum <= m
        max = [max, current_sum].max
        break
      end
    end

    pq << a
    pq.sort!
  end

  vec << max
end

vec.each do |v|
  puts v.zero? ? 'NONE' : v
end



Measured memory_bytes: 26192
#include <iostream>
using namespace std;
int main()
{
    int a[3], flag1=0, flag2=0;
    for(int i = 0; i < 3; i++)
    { cin >> a[i]; if(a[i] == 5) flag1+=1; else if(a[i] == 7) flag2+=1; }
    if(flag1 == 2 && flag2 == 1) cout << ("YES\n");
    else cout << ("NO\n");
}


Measured memory_bytes: 256
n,k = map(int,input().split())

a_list =[]
for i in range(k):
    d = int(input())
    a = list(map(int,input().split()))
    a_list = a_list + a

t = 0
for i in range(1,n+1):
    if i in a_list:
        t += 1
print(n-t)

Measured memory_bytes: 9188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int r = Integer.parseInt(in.next());
            double ans = 0;

            ans = 2 * Math.PI * r;

            // 出力
            out.printf("%.8f%n", ans);


        }

    }
}



Measured memory_bytes: 36016
#include <iostream>
#include <vector>
using namespace std;
typedef int64_t int64;
#define print(x) cout << (x) << '\n'
 
int main(){
 int n, k; cin >> n >> k;
 int64 a[n];
 for (int i = 0; i < n; ++i) cin >> a[i];
 
 int64 s[n]; s[0] = a[0];
 for (int i = 1; i < n; ++i) s[i] = s[i - 1] + a[i];
 vector<int64> v;
 
 for (int i = 0; i < n; ++i) v.push_back(s[i]);
 for (int i = 0; i < n; ++i){
   for (int j = i + 1; j < n; ++j) v.push_back(s[j] - s[i]);
 }
 
 int64 ans = 0;
 for (int bit = 39; bit >= 0; --bit){
   int64 p = ((int64)1<<bit);
   int cnt = 0;
   
   for (int i = 0; i < (int) v.size(); ++i){
     if (((ans + p) & v[i]) == ans + p) ++cnt;
   }
   if (cnt >= k) ans += p;
 }
 print(ans);
 
 return 0;
}

Measured memory_bytes: 6512
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>
    #include<cstdint>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;

    int main(){
        string s;cin>>s;
        map<char,int>mp;
        rep(i,s.size()){
            mp[s[i]]++;
        }
        for(auto m:mp){
            if(m.second!=2){cout<<"No";return 0;}
        }
        cout<<"Yes";
    }
    


Measured memory_bytes: 256
def gcd(aa, bb):
    if aa % bb == 0:
        return bb
    return gcd(bb, aa % bb)

import sys
for line in sys.stdin.readlines():
    ab = list(map(int, line.split()))
    a = max(ab)
    b = min(ab)
    g = gcd(a, b)

    print(g, a * b // g)


Measured memory_bytes: 5592
#include <iostream>
using namespace std;
int isPrime[2000001];
int main(){

  fill(isPrime,isPrime + 2000001,1); 
  isPrime[0]=isPrime[1]=0;
  for(int i = 2 ; i*i < 2000001 ; i++ ){
    if(isPrime[i])for(int j = i*2 ; j < 2000001 ; j+=i )isPrime[j] = 0;
  }
  int n;
  while(cin >> n,n){
    int cnt = 0;
    int p,q;
    for(int i = n ; ; i++){
      if(isPrime[i] == 1){
	p = i;
	break;
      }
    }
    int f = 1;
    for(int i = n ; ; i--){
      if(i < 0){
	f = 0;
	break;
      }
      if(isPrime[i] == 1){
	q = i;
	break;
      }
    }
    if(f == 0)cout << 0 << endl;
    else cout << p-q << endl;
  }
  return 0;
}

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

int main() {
    char c;
    cin >> c;
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int A, B;

void solve() {
	cin >> A >> B;
	cout << (B - 1 + A - 1 - 1) / (A - 1) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, m; cin >> n >> m;
	vector<vi> v(n, vi(m));
	rep(i, n) rep(j, m) cin >> v[i][j], v[i][j]--;
	
	vi use(m, 1);
	int ans = inf;
	rep(i, m){
		vi cnt(m);
		rep(j, n) rep(k, m) if(use[v[j][k]]){
			cnt[v[j][k]]++; break;
		}
		int mxi = max_element(all(cnt)) - cnt.begin();
		ans = min(ans, cnt[mxi]);
		use[mxi] = 0;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#include <algorithm>
#include <cinttypes>
#include <cstdio>
#include <vector>

using namespace std;
template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int N, K;

int64_t ans = 0;

vector<int> A;
vector<int> B;

int main()
{
    gc(N);
    gc(K);

    for (int i = 0; i < N; i++)
    {
        int a, b;
        gc(a);
        gc(b);
        A.push_back(a);
        B.push_back(b);
    }

    int d = 30;
    bool init = true;
    while (0 <= d)
    {
        int64_t tmp = 0;
        if ((K & 1 << d) || (K == 0 && d == 0))
        {
            tmp = 0;
            if (init)
            {
                // ビットパターンが一致
                for (int i = 0; i < N; i++)
                {
                    if ((A[i] | K) == K) tmp += B[i];
                }
                ans = max(ans, tmp);
                init = false;
            }

            tmp = 0;

            // 自分のフラグを倒す、自分を除く上位ビットのフラグ保持
            // 自分を除く下位ビットのフラグを立てる
            int k = K != 0 ? K ^ (1 << d) | (1 << d) - 1 : 0;

            for (int i = 0; i < N; i++)
            {
                if ((A[i] | k) == k) tmp += B[i];
            }
            ans = max(ans, tmp);
        }
        d--;
    }

    printf("%" PRId64 "\n", ans);
    return 0;
}


Measured memory_bytes: 1276
from collections import Counter

N, M = map(int, input().split())

KS= set([])
for i in range(N):
    IA = list(map(int, input().split()))
    if i == 0:
        KS = set(IA[1:])
    else:  
        KS = KS.intersection(set(IA[1:]))

print(len(KS))


Measured memory_bytes: 3316
import numpy as np 
import itertools
N = int(input())
pos = []
for _ in range(N):
    pos.append(list(map(int,input().split())))
pos = np.array(pos)

dist_dict = {}
def dist(n0,n1): # inputはノード番号
    k = str(min(n0,n1))+str(max(n0,n1))
    if k in dist_dict:
        d = dist_dict[k]
    else:
        d = np.sqrt(np.sum(np.power(pos[n1]-pos[n0],2)))
        dist_dict[k] =d
    return d

pattern_list = list(itertools.permutations(range(N))) # 順列の生成
ans = 0
for pattern in pattern_list:
    pre_node = pattern[0]
    for i in range(1,N):
        next_node = pattern[i]
        ans+=dist(pre_node,next_node)
        pre_node = next_node

for i in range(1,N+1):
    ans /= i

print(ans)

Measured memory_bytes: 19972
s=str(input())
s=list(s)
ans=1
i=1
temp=s[0]
while True:
  if s[i]!=temp:
    ans=ans+1
    temp=s[i]
    i=i+1
  elif s[i]==temp and i==len(s)-1:
    i=i+1
  else:
    temp=s[i]+s[i+1]
    i=i+2
    ans=ans+1
  if i>len(s)-1:
    break
print(ans)

Measured memory_bytes: 4840
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

struct vw_pair
{
    int v, w;
    vw_pair(int v, int w) : v(v), w(w){};
};

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vector<vw_pair>> adj_list;
typedef vector<bool> vb;
typedef int_fast64_t ll;
typedef uint_fast64_t ul;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;

#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1 << n) - 1)
#define modulo(S, N) ((S) & (N - 1)) // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S - 1))
#define turnOnLastZero(S) ((S) | (S + 1))
#define turnOffLastConsecutiveBits(S) ((S) & (S + 1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S - 1))
#define in_range(lo, hi, x) ((x >= lo && x <= hi))
#define numberOfOnBit(x) __builtin_popcountll(x)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forsn(i, x, n) for (int i = x; i < int(n); i++)
double esp = 1e-6;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

// Hash map for long long
gp_hash_table<long long, int, custom_hash> ll_hash_map;
// Simple hash for pair
struct chash
{
    int operator()(ii x) const { return x.first * 31 + x.second; }
};
gp_hash_table<ii, int, chash> pair_hash_map;

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

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;cin >> n;
    vi P(n,0);
    vi Q(n,0);
    forn(i,n) {
        cin >> P[i];--P[i];
        Q[P[i]] = i;
    }
    int max_range = 1;
    int l=0;
    while (l < (n-1)) {
        int r = l+1;
        while (r < n && Q[r] > Q[r-1]) ++r;
        max_range = max(max_range, r-l);
        l = r;
    }
    cout << n - max_range << "\n";

    return 0;
}


Measured memory_bytes: 1792
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int a, b, c;
    cin >> a >> b >> c;

 	vi v(10);
 	v[a]++; v[b]++; v[c]++;

 	int one = 0, two = 0;
 	rep (i, 1, 9) {
 		if (v[i]==1) one++;
 		if (v[i]==2) two++;
 	} 
 	if (two==1 && one==1) cout << "Yes";
 	else cout << "No";
 	cout << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	cout<<(a*a)-b;
	
	return 0;
}

Measured memory_bytes: 256
using System;
//using System.Collections;
//using System.Collections.Generic;
//using System.Linq;

namespace solution
{
  class Class1
  {
    static void Main()
    {
      string s1 = "abcdefghijklmnopqrstuvwxyz";
      string s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      int count = 0;
      string line = "";
      string ss = "";

      while ((line = Console.ReadLine()) != null)
      {
        ss += line;
      }

      for (int i = 0; i < 26; i++)
      {
        for (int j = 0; j < ss.Length; j++)
        {
          if (s1[i] == ss[j] || s2[i] == ss[j]) count++;
        }
        Console.WriteLine("{0} : {1}", s1[i], count);
        count = 0;
      }
    }
  }
}


Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

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


void solve(long long A, long long B, long long C, long long K){
    ll ans = 0;
    if(K > 0){
       ans += min(K,A); 
       K -= A;
    }
    if(K > 0){
        K -= B;
    }
    if(K > 0){
        ans -= min(K,C);
        K -= C;
    }
    cout << ans << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
# define ll long long
using namespace std;
int main(){
ll n,ans=0;
  cin>>n;
  string s;
  cin>>s;
  ans=1;
  for(int i=1;i<n;i++) if(s[i]!=s[i-1]) ans+=1;
  cout<<ans<<endl;
}

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

using namespace std;

void zenbu(int rest, int maxim, vector<int> v){
	if(rest == 0){
		for(int i = 0; i < v.size(); i++){
			if(i == 0){
				printf("%d", v.at(i));
			}else{
				printf(" %d", v.at(i));
			}
		}
		printf("\n");
		return;
	}
	for(int i = min(rest, maxim); i > 0; i--){
		v.push_back(i);
		zenbu(rest - i, i, v);
		v.erase(v.end() - 1);
	}
}

int main(){
	
	int n;
	
	vector<int> v;
	
	while(true){
		cin >> n;
		if(n == 0){
			break;
		}
		zenbu(n, n, v);
	}
	
	return 0;
}

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

bool binary_search(int x, int S[], int N){
	int left = 0;
	int right = N - 1;
	while(left <= right){
		int mid = (left + right) / 2;
		if(S[mid] == x){
			return true;
		}else if(S[mid] < x){
			left = mid + 1;
		}else{
			right = mid - 1;
		}
	}
	return false;
}

int main(){
	int n, q, cnt=0;
	cin >> n;
	int S[n];
	for(int i = 0; i < n; i++){
		cin >> S[i];
	}
	cin >> q;
	int T[q];
	for(int i = 0; i < q; i++){
		cin >> T[i];
	}
	for(int i = 0; i < q;i++){
		if(binary_search(T[i],S,n)){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

struct Info
{
    string first;
    ll second;
    ll num;
};

bool cmp(const Info &a, const Info &b)
{
    if (a.first < b.first)
        return true;
    else if (a.first == b.first)
    {
        if (a.second > b.second)
            return true;
        else
            return false;
    }
    else
        return false;
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<Info> p(n);
    REP(i, n)
    {
        cin >> p[i].first >> p[i].second;
        p[i].num = i + 1;
    }
    sort(ALL(p), cmp);
    REP(i, n)
    cout << p[i].num << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    new Main().run();
  }
  void run() {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int sum = a + b;
    if(sum%2 != 0) {
      System.out.println(sum/2+1);
    }else {
      System.out.println(sum/2);      
    }
  }
}


Measured memory_bytes: 25300
package main

import(
	"bufio"
	"strconv"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(x int, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func max(x int, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b, c, d := nextInt(), nextInt(), nextInt(), nextInt()

	if c > b || a > d {
		fmt.Println(0)
		return
	}

	second := min(b, d) - max(a, c)



	fmt.Println(second)
}

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

const int MOD = 1000000007;
int N;
vector<map<string,int> > dp;
char res[4] = {'A','T','G','C'};
// dp[i][atgc] : i文字までの、直前三文字がatgcであるものの種類
// atgcを用いて、部分文字列として　GAC, ACG, A?CG, AG?Cを含まないようにdpを更新していく。

bool check(string temp){
    for(int i=0;i<4;++i){
        string t = temp;
        if(i>=1) swap(t[i-1],t[i]);
        if((t[0]=='A' && t[1]=='G' && t[2]=='C') || (t[1]=='A' && t[2]=='G' && t[3]=='C')){
            return false; // ダメな文字列が出現
        } 
    }
    return true;
}

// メモカさいき
int rec(int cur, string atgc){
    if(dp[cur][atgc]) return dp[cur][atgc];
    if(cur==N) return 1;


    int ret = 0;
    for(char r : res){
        string temp = atgc + r;
        if(check(temp)){
            temp.erase(temp.begin());
            ret = (ret + rec(cur+1,temp)) % MOD;
        }
    }

    return dp[cur][atgc] = ret;
}

int main(void){
    cin >> N;
    dp.resize(N+1);

    cout << rec(0,"TTT") << endl;
    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end



int main(){
   int n,m; scanf("%d%d",&n,&m);
   vector<int> cnt(n,0); int res=0,res2=0;
   rep(i,0,m){
      int tmp; scanf("%d",&tmp); tmp--;
      string s; cin>>s;
      if(cnt[tmp]==-1)continue;
      if(s[0]=='W')cnt[tmp]++;
      else{
         res++;
         res2+=cnt[tmp]; cnt[tmp]=-1;
      }
   }
   printf("%d %d\n",res,res2);
   return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;
typedef long long ll;

const ll MAXN=2e5+2+5;

ll chct[MAXN];
int last[26];
int N;
string A;

int main() {
        cin >> A;
        N = A.size();

        for (int i=0; i<26; ++i)
                last[i] = -1;

        for (int i=N-1; i>=0; --i) {
                if (last[A[i]-'a'] == -1)
                        chct[i] = 1;
                else
                        chct[i] = chct[last[A[i]-'a']]+1;
                last[A[i]-'a'] = i;
        }

        ll tot=1;
        for (int i=0; i<N; ++i)
                tot += N-i-chct[i];

        cout << tot << "\n";
}

Measured memory_bytes: 2180
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int H = scan.nextInt();
		int A = scan.nextInt();
		int count = 0;

		while(H > 0) {
			H-=A;
			count++;
		}

		System.out.println(count);
	}
}


Measured memory_bytes: 23252
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20
MOD = 10**9 + 7
def combmod(n, k, mod=MOD):
    if k == 0:
        return 1
    if k == 1:
        return n
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

def main():
    n, k = getList()
    if k >= n-1:
        ans = combmod(n+n-1, n)
    else:
        # ans = 0
        ans = 1
        tmp = 1
        for i in range(1, k+1):
            tmp *= n-i
            tmp *= n + 1 - i
            tmp *= pow(i, MOD-2, MOD)
            tmp *= pow(i, MOD - 2, MOD)
            ans += tmp
            tmp %= MOD
            # tmp = combmod(n-1, i)
            # tmp *= combmod(n, i)
            # tmp %= MOD
            # ans += tmp
            ans %= MOD
        # ans = combmod(n, k+1)
        # print(ans)
        # ans *= combmod(k+k+1, k+1)
        # # ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 40428
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

ostream& operator << (ostream& os, const mint a) {
    os << a.x;

    return os;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N, M;
    cin >> N >> M;

    vi S(N), T(M);
    REP(i, N) cin >> S[i];
    REP(j, M) cin >> T[j];

    vector<vector<mint>> dp(N + 1, vector<mint>(M + 1, 0));

    REP(i, N + 1) dp[i][0] = 1;
    REP(i, M + 1) dp[0][i] = 1;

    FOR(i, 1, N+1) {
        FOR(j, 1, M+1) {
            dp[i][j] += dp[i - 1][j];
            dp[i][j] += dp[i][j - 1];
            if (S[i - 1] != T[j - 1]) {
                dp[i][j] -= dp[i - 1][j - 1];
            }
        }
        debug(i, dp[i])
    }

    print(dp[N][M]);

}


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

using namespace std;
int main(){
	int q,a,b;
	string s;
	cin>>q;
	set<string>m;
	for(;q--;){
		cin>>a;
		if(a==0)cin>>s,m.insert(s),cout<<m.size()<<endl;
		if(a==1)cin>>s,cout<<m.count(s)<<endl;
		if(a==2)cin>>s,m.erase(s);
	}
}




Measured memory_bytes: 21884
H,W=map(int,input().split())
answer=0
if not H%3==0 and not W%3==0:
  S_1=[H//3*W,(H-H//3)*(W//2),(H-H//3)*(W-W//2)]
  S_2=[(H//3+1)*W,(H-H//3-1)*(W//2),(H-H//3-1)*(W-W//2)]
  S_3=[W//3*H,(W-W//3)*(H//2),(W-W//3)*(H-H//2)]
  S_4=[(W//3+1)*H,(W-W//3-1)*(H//2),(W-W//3-1)*(H-H//2)]
  answer=min(max(S_1)-min(S_1),max(S_2)-min(S_2),max(S_3)-min(S_3),max(S_4)-min(S_4),H,W)
print(answer)

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

int main() {
    int a, b;
    cin >> a >> b;
    bool x, y, z;
    x = 1, y = 1, z = 1;
    if(a == 1)x = 0;
    if(a == 2)y = 0;
    if(a == 3)z = 0;
    if(b == 1)x = 0;
    if(b == 2)y = 0;
    if(b == 3)z = 0;
    if(x)cout << 1 << endl;
    if(y)cout << 2 << endl;
    if(z)cout << 3 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
char arr[3][3],i,j;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>arr[i][j];
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(i==j)
cout<<arr[i][j];
}
}

return 0;  
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

map<ll, set<ll>> ma;

int main(){
	ll H, W, N;
	cin >> H >> W >> N;
	ll X, Y;
	REP(i, N){
		cin >> X >> Y;
		ma[X].insert(Y);
	}
	ll left = 1;
	ll right = 1;
	ll res = H;

	for(int i=2;i<=H;i++){
		if(ma[i].empty()) right = min(right+1, W);
		else{
			ll f = *ma[i].begin();
			if(left<=f && f<=right){
				res = i-1;
				break;
			}
			if(f!=right+1) right = min(right+1, W);
		}
	}

	cout << res << endl;

    return 0;
}

Measured memory_bytes: 28416
#include<stdio.h>
int C;
char p[201000];
int main(){
    int i , c = 0, r = 0;
    scanf("%s",p);
    for(i=0;p[i];i++){
        r++;
        if(p[i]=='S')c++;
        else{
            if(c){
                r-=2;
                c--;
            }
        }
    }
    printf("%d\n",r);
}


Measured memory_bytes: 384
Scanf.scanf "%d %d" (fun n m ->
    let x = Array.init m (fun _ -> Scanf.scanf " %d" (fun x -> x)) in
    Array.sort compare x;
    let xd = Array.init (m - 1) (fun i -> x.(i + 1) - x.(i)) in
    Array.sort compare xd;
    let rec loop i acc =
        if i < max 0 (m - n) then acc else
            loop (i - 1) (acc - xd.(i))
    in
    loop (m - 2) (x.(m - 1) - x.(0)) |> Printf.printf "%d\n"
)

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#include <math.h>
#include <time.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

int main(){
    ll n; cin >> n;
    vector<ll> a(n),b(n),c(n);
    rep(i,n) cin >> a.at(i);
    rep(i,n) cin >> b.at(i);
    rep(i,n) cin >> c.at(i);
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    vector<ll> bb(n);
    rep(i,n){
        auto it = upper_bound(c.begin(),c.end(),b.at(i));
        ll amt = n - (it-c.begin());
        bb.at(i) = amt;
    }
    //cout << "ck1" << endl;
    vector<ll> rui(n);
    rui.at(n-1) = bb.at(n-1);
    for(int i=n-2;i>=0;i--){
        rui.at(i) = rui.at(i+1) + bb.at(i); 
    }
    ll ans = 0;
    //cout << "ck2" << endl;
    rep(i,n){
        auto it = upper_bound(b.begin(),b.end(),a.at(i));
        ll amt = it-b.begin();
        if(amt==n) continue;
        ans += rui.at(amt);        
    }
    /*
    rep(i,n) cout << bb.at(i) << " ";
    cout << endl;
    rep(i,n) cout << rui.at(i) << " ";
    cout << endl;
    */
    cout << ans << endl;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <math.h>

int n, p[8];
double mat[8][8];
double sum = 0.0;

int rec(int idx);
int calcP(void);

int main(void)
{
	int p[8][2];
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		scanf("%d %d%*c", &p[i][0], &p[i][1]);
	}

	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) {
			if(i==j) continue;
			double t = sqrt((p[i][0]-p[j][0])*(p[i][0]-p[j][0]) + (p[i][1]-p[j][1])*(p[i][1]-p[j][1]));
			mat[i][j] = t;  mat[j][i] = t;
		}
	}

	rec(0);
	printf("%lf", sum/calcP());

	return 0;
}

int calcP(void)
{
	int a = 1;
	for(int i=1;i<=n;i++)
		a *= i;
	return a;
}

int exist(int idx, int m)
{
	for(int i=0;i<idx;i++) {
		if(p[i] == m) return 1;
	}
	return 0;
}

double calc(void)
{
	double s = 0.0;
	for(int i=1;i<n;i++) {
		s += mat[p[i-1]][p[i]];
	}
	return s;
}

int rec(int idx)
{
	for(int i=0;i<n;i++) {
		if(exist(idx, i)) continue;
		p[idx] = i;
		if(idx == n-1) {
			sum += calc();
		} else {
			rec(idx+1);
		}
	}
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define W(i, j) ((i) ? (j) : 0)

using namespace std;

int main(){
  double a;
  while(scanf("%lf", &a) && a > 0){
    bool f = false;
    rep(i, 2) rep(j, 2) rep(k, 2) rep(l, 2) rep(m, 2) rep(n, 2) rep(o, 2) rep(p, 2) rep(q, 2) rep(r, 2) rep(s, 2) rep(t, 2)
      if(W(i,128)+W(j,64)+W(k,32)+W(l,16)+W(m,8)+W(n,4)+W(o,2)+W(p,1)+W(q,0.5)+W(r,0.25)+W(s,0.125)+W(t,0.0625) == a){
	printf("%d%d%d%d%d%d%d%d.%d%d%d%d\n",i,j,k,l,m,n,o,p,q,r,s,t);
	f = true;
      }
    if(!f) puts("NA");
  }
  return 0;
}

Measured memory_bytes: 1072