akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
public class Main
{
    static BufferedReader br;
    static BufferedWriter bw;
    static void solve()throws Exception
    {
        Scanner S = new Scanner(System.in);
        int  n = S.nextInt();
        long k = S.nextLong();
        int A[] = new int[n];
        for(int i=0;i<n;i++)
        A[i] = S.nextInt()-1;
        ArrayList<Integer> al = new ArrayList<Integer>();
        HashSet<Integer> hs  = new HashSet<Integer>();
        ArrayList<Integer> ans = new ArrayList<Integer>();
        int ptr = 0;
        for(int i=0;i<Math.min(k,n);i++)
        {
            if(hs.contains(ptr))
            break;
            al.add(A[ptr]);
            hs.add(ptr);
            ptr = A[ptr];
        }
        int noncycle = al.size();
        hs = new HashSet<Integer>();
        while(!hs.contains(ptr))
        {
            ans.add(ptr);
            hs.add(ptr);
            ptr = A[ptr];
        }
        if(k<=noncycle)
        {
            bw.write(Integer.toString(al.get((int)k-1)+1));
        }
        else
        bw.write(Integer.toString(ans.get((int)((k-noncycle)%ans.size()))+1));
        // System.out.println(al);
    }
    public static void main(String []args)throws Exception
    {
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));
        solve();
        br.close();
        bw.close();
    }
}

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

int main() {
  string s;
  cin >> s;
  int len = s.size();
  
  int ordered = 0;
  bool out = false;
  ll int ans = 0;
  rep(i, len) {
    char x = s[i];
    if(!out) {
      if(x == 'B') out = true;
      else ++ordered;
    }
    
    if(out && x=='W') {
      ans = ans + i - ordered;
      ++ordered;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		long cnt = 0;
		for(int i = 1; i <= n; i++){
			if(i % 3 != 0 && i % 5 != 0) cnt += i;
		}
		System.out.println(cnt);
		scanner.close();
	}

}


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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    ll n, m, k; cin >> n >> m >> k;
    vl a(n), b(m);
    for(ll& u : a) cin >> u;
    for(ll& u : b) cin >> u;
    for(ll i = 1; i < n; i++)
        a[i] += a[i-1];
    for(ll i = 1; i < m; i++){
        b[i] += b[i-1];
    }
    ll j = m - 1;
    while(j >= 0 && b[j] > k) j--;
    ll ans = j + 1;
    for(ll i = 0; i < n; i++){
        if(a[i] > k)
            break;
        while(j >= 0 && b[j] + a[i] > k) j--;
        ans = max(ans, i + 1 + j + 1);
    }
    cout << ans << '\n';
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
// 	precompute();
	for(int i = 1; i <= t; i++){
	   // cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 6368
N, M, Q = map(int, input().split())
areas = [[0 for _ in range(N + 2)] for _ in range(N + 2)]

for _ in range(M):
    left, right = map(int, input().split())
    areas[left][right] += 1
# print(areas)
for i in range(1, N + 2):
    for j in range(1, N + 2):
        areas[i][j] += areas[i][j - 1]
# print(areas)
for _ in range(Q):
    left, right = map(int, input().split())
    cost = 0
    for i in range(left, right + 1):
        cost += areas[i][right] - areas[i][left - 1]
    print(cost)


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

int a[1000001];
int cnt = 0;

void insertionSort( int N, int g );
void shellSort( int N );

int main(){
  int N; cin >> N;
  for( int i = 0; i < N; i++ ){
    cin >> a[i];
  }

  shellSort( N );

  for( int i = 0; i < N; i++ ){
    cout << a[i] << endl;;
  }
}

void insertionSort( int N, int g ){
  for( int i = g; i < N; i++ ){
    int key = a[i];
    int j = i - g;
    while( j >= 0 && a[j] > key ){
      a[j + g] = a[j];
      j -= g;
      cnt++;
    }
    a[j + g] = key;
  }
}

void shellSort( int N ){
  int h = 1;
  int m = 0;
  for( int h_tmp = 1; h_tmp < N; h_tmp = h_tmp * 3 + 1 ) h = h_tmp;

  int h_tmp = h;
  while( h_tmp > 0 ) h_tmp /= 3, m++;
  cout << m << endl;
  
  for( int i = 0; i < m; i++ ){
    insertionSort( N, h );
    cout << h;
    if( i == m - 1 ) cout << endl;
    else cout << " ";
    h /= 3;
  }
  cout << cnt << endl;
  
}



Measured memory_bytes: 6984
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int k = sc.nextInt();
		String s = sc.next();

		if (s.length() <= k){
			System.out.println(s);
		} else {
			System.out.println(s.substring(0, k) + "...");
		}



	}


}

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

using namespace std;
using ll = long long;

int main()
{
    ll P;
    cin >> P;

    vector<ll> A(P);
    for(ll i=0; i<P; ++i) cin >> A[i];

    vector<ll> C(P);
    ll s, t;
    C[0] = 1;    
    for(ll i=1; i<P; ++i){
        C[i] = 1; t = 1;
        for(ll j=1; j<i; ++j){
            s = (t + C[j]) % P; t = C[j]; C[j] = s;
        }
    }

    vector<ll> B(P);
    ll k;
    B[0] = A[0] * 1; B[P-1] = A[0] * (-1);
    for(ll i=1; i<P; ++i){
        if(!A[i]) continue;
        k = 1;
        for(ll j=0; j<P-1; ++j){
            B[P-1-j] -= (C[j] * k) % P;
            k = (k * (-i)) % P;
        }
    }

    ll b;
    for(ll i=0; i<P; ++i){
        b = B[i] % P;
        B[i] = (b >= 0 ? b : b + P); 
        cout << B[i] << " ";
    }
    cout << endl;

    return 0;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int  n , k; cin>>n>>k;
    string s ; cin>>s;
    s[k - 1] = tolower(s[k - 1] , locale());
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;

int n, m, k;
int C[MX];
ll ans;
struct edge {
	int u, v, co;
	bool operator < (const edge &e) const {
		return co<e.co;
	}
};
vector<edge> E;

int U[MX];
int find(int x){
	return x==U[x] ? x : U[x]=find(U[x]);
}
void unite(int x, int y){
	U[find(y)]=find(x);
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m>>k;
    for(int i=1; i<=n; i++) cin>>C[i];
    for(int i=1; i<=m; i++){
    	int u,v,c; cin>>u>>v>>c;
    	E.push_back({u,v,c});
	}
	iota(U, U+n+1, 0);

	vector<int> P[MX];
	for(int i=1; i<=n; i++) P[C[i]].push_back(i);
	for(int i=1; i<=k; i++)
		for(int x:P[i])
			unite(x, P[i][0]);

	sort(E.begin(), E.end());

	int cnt=0;
	for(edge &e:E){
		int u=e.u, v=e.v, c=e.co;
		if(cnt>=k-1 || find(u)==find(v)) continue;
		cnt++;
		unite(u,v);
		ans+=c;
	}
	cout<<(cnt<k-1 ? -1 : ans);
    return 0;
}

Measured memory_bytes: 7668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

int main()
{
    ll x,y;
    ll sum = x;
    cin >> x >> y;
    if(x%y==0){
        cout << -1 << endl;
    }else{
        cout << x << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    double n,m,d;cin>>n>>m>>d;
    if(d==0){
        printf("%.10lf\n",(m-1)/n);
    }else{
        printf("%.10lf\n",(m-1)*2*(n-d)/(n*n));
    }
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define MP make_pair
#define PB push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
const double EPS = 1e-9;
const int INF = 1<<28;
const double PI = acos(-1.0);
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

bool vpos(int x,int y,int w,int h){return 0<=x&&x<w&&y>=0&&y<h;}

typedef pair<int,pair<int,int> > E;

struct UnionFind{
    vector<int> par;
    UnionFind(int n){
        REP(i,n)par.push_back(i);
    }

    int find(int x){
        if(par[x]==x)return x;
        return par[x] = find(par[x]);
    }

    void union_(int x,int y){
        x = find(x);
        y = find(y);
        par[x] = y;
    }

    bool same(int x,int y){
        return find(x) == find(y);
    }
};

int main(){
    for(;;){
        int n,m;
        vector<E> es;
        cin >> n >> m;
        if(!n)break;
        UnionFind uf(n);
        REP(i,m){
            char conma;
            int a,b,d;
            cin >> a >> conma >> b >> conma >> d;
            es.PB(MP(d,MP(a,b)));
        }
        int sum = 0;
        sort(ALL(es));
        for(int i=0;i<m;i++){
            E e = es[i];
            int a = e.second.first;
            int b = e.second.second;
            int d = e.first;
            if(uf.same(a,b))continue;
            uf.union_(a,b);
            sum+=d/100-1;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

vector<pair<int, int>> edge[100010];
ll dist[100010];
void dfs(int v, int p) {
    for (auto pr : edge[v]) {
        int nv = pr.first;
        int c = pr.second;
        if (nv == p) continue;
        dist[nv] = dist[v] + c;
        dfs(nv, v);
    }
}

int main() {
    int n;
    cin >> n;
    rep(i, 0, n - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edge[a].push_back(make_pair(b, c));
        edge[b].push_back(make_pair(a, c));
    }

    int q, k;
    cin >> q >> k;
    k--;
    dfs(k, -1);

    int x[q], y[q];
    rep(i, 0, q) {
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    rep(i, 0, q) {
        cout << dist[x[i]] + dist[y[i]] << endl;
    }
    return 0;
}


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

int main(void){
  int i,u,n,x,c=0;
  int a[200001];
  stack<int> s;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&x);
    s.push(x);
  }

  for(i=0;i<n;i++){
    u=s.top(); s.pop();
    if(i%2==0){
      a[i/2]=u;
   }
    else{
      a[n-i/2-1]=u;
   }
  }

  for(i=0;i<n;i++)
    printf("%d ",a[i]);
  printf("\n");

  return 0;

}


Measured memory_bytes: 3484
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e15;

int main()
{
    string s;
    cin >> s;
    ll n=s.length();
    ll ans=0;
    rep(i,n){
        if(s[i]=='+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define print(v); for(auto x:v) cout<<x<<" "; cout<<endl;
typedef long long int ll;

ll nCr(ll n, ll r) 
{
    long long p = 1, k = 1; 
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            long long m = __gcd(p, k); 
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
    } 
    else
        p = 1; 
    return p;
}
int main()
{
    fast;
    ll n;
    cin >> n;
    long long arr[n + 1]; 
    unordered_map<ll, ll> umap;
    for(ll i = 0; i < n; i++){
        cin >> arr[i];
        umap[arr[i]]++;
    }
    ll count = 0;
    for(auto x: umap){
        if(x.second > 1){
            count = count + nCr(x.second, 2);
        }
    }
    // cout << count << endl;
    ll ans;
    for(ll i = 0; i < n; i++){
        umap[arr[i]]--;
        ans = count - umap[arr[i]];
        umap[arr[i]]++;
        cout << ans << endl;
    }
    cout << endl;



    return 0;
}

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

int main(void){
	int n,m,d;
	cin >> n >> m >> d;
	long double a,b,c;// ans = a*b/n^2;
	double res;
	if(d==0)res = (long double)(m-1)/n;
	else res = (long double)(m-1)*2*(n-d)/n /n;
	cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import sys

N = int(sys.stdin.readline())


def Base_10_to_n(X, n):
    m = chr(X%n+ord("a"))
    if (X//n):
        return Base_10_to_n(X//n-1, n)+m
    return m

print(Base_10_to_n(N-1,26))


Measured memory_bytes: 9168
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[100][100] = {};
int color[100] = {}, d[100], f[100], t=0;

void dfs(void);

void dfs_visit(int);

int main() {
	int u,v, k,i,j;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		u--;
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			v--;
			M[u][v]=1;
		}
	}
	dfs();
	return 0;
}

void dfs(void) {
	int u;
	for (u = 0; u < n; u++) {
		if (color[u] == WHITE) {
			dfs_visit(u);
		}
	}
	for (u = 0; u < n; u++) {
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
}

void dfs_visit(int u) {
	int v;
	color[u] = GRAY;
	d[u] = ++t;
	for (v = 0; v < n; v++) {
		if (M[u][v] == 0) {
			continue;
		}
		if (color[v] == WHITE) {
			dfs_visit(v);
		}
	}
	color[u] = BLACK;
	f[u] = ++t;
}


Measured memory_bytes: 2104
#coding:utf-8
import sys
N,K=map(int,raw_input().split())

if K>sum(range(1,N-2+1)): # 1+...+(n-2)
    print(-1)
    sys.exit(0)
F=[]
for i in range(2,N+1):
    F.append((1,i))
n=sum(range(1,N-2+1))-K

c=0
for i in range(2,N+1):
    for j in range(i+1,N+1):
        if(c<n):
            F.append((i,j))
            c+=1
        else:
            break

print(len(F))
for u,v in F:
    print("%d %d"%(u,v))


Measured memory_bytes: 2948
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << "0\n"; return;}
#define mkp make_pair

void solve() {
    string s;
    cin >> s;
    if (s == "ABC")
        cout << "ARC";
    else
        cout << "ABC";
}

signed main() {
    srand(time(NULL));
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int res = 0;
    for (int i = 1; i <= n; i++) {
        int s = 0;
        int x = i;
        while (x) {
            s += x % 10;
            x /= 10;
        }
        if (a <= s && s <= b) {
            res += i;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
const int M=998244353;
const int inv2=(M+1)/2;
const int inv3=(M+1)/3;
const int maxn=3e5+3;
vector <int> h[maxn];
int dis[maxn],n,pre[maxn],p,q,d[maxn],m;
ll dp[maxn][4];
void dfs(int u,int fa){
    pre[u]=fa; dis[u]=dis[fa]+1;
    for (auto v:h[u]){
        if (v==fa) continue;
        dfs(v,u);
    }
}
void dfs2(int u,int fa){
    d[u]=d[fa]+1;
    if (d[u]==m){
        dp[u][0]=2; // none
        dp[u][1]=1; // exactly one
        dp[u][2]=3; // all
        dp[u][3]=1; // at least one
        return;
    }
    ll r1=1,r2=0,r3=1,r4=0;
    for (auto v:h[u]){
        if (v==fa) continue;
        dfs2(v,u);
        ll nr1=r1*dp[v][0]%M;
        ll nr2=(r1*dp[v][1]+r2*dp[v][0])%M;
        ll nr3=r3*dp[v][2]%M;
        ll nr4=((r3*dp[v][3]+r4*dp[v][2]-r4*dp[v][3])%M+M)%M;
        r1=nr1; r2=nr2; r3=nr3; r4=nr4;
    }
    dp[u][0]=(r1*3+r4*2)%M;
    dp[u][1]=r2;
    dp[u][2]=r3*3%M;
    dp[u][3]=r4;
}
int main(){
    scanf("%d",&n); dis[0]=-1;
    for (int i=1;i<n;i++){
        int u,v; scanf("%d%d",&u,&v);
        h[u].pb(v); h[v].pb(u);
    }
    //puts("B");
    dfs(1,0);
    int s=1;
    for (int i=2;i<=n;i++) if (dis[i]>dis[s]) s=i;
    dfs(s,0);
    int t=s;
    for (int i=1;i<=n;i++) if (dis[i]>dis[t]) t=i;
    m=dis[t]/2; p=t;
    for (int i=0;i<m;i++) p=pre[p];
    if (dis[t]&1){
        q=pre[p];
        d[q]=-1; dfs2(p,q);
        d[p]=-1; dfs2(q,p);
        printf("%lld\n",dp[p][1]*dp[q][1]%M);
    } else {
        ll ans0=1,ans1=0,ans2=0;
        for (auto u:h[p]){
            d[u]=0; dfs2(u,p);
            ll nans0,nans1,nans2,has,none;
            has=dp[u][1]; none=(dp[u][2]+2*(M-dp[u][3]))%M;
            //cout<<has<<' '<<none<<endl;
            //cout<<dp[u][2]<<' '<<dp[u][3]<<endl;
            nans0=ans0*none%M;
            nans1=(ans0*has+ans1*none)%M;
            nans2=(ans1*has+ans2*none)%M;
            ans0=nans0; ans1=nans1; ans2=nans2;
        }
        printf("%lld\n",ans2);
    }
    return 0;
}


Measured memory_bytes: 31232
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<bitset>
#include<utility>

typedef long long ll;
#define INF 1000000000
#define MOD 1000000007

using namespace std;

ll dp[100][2];

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> k(n);
	vector<vector<int>> a;
	a.resize(n);
	for (int i = 0; i<n; i++) {
		cin >> k[i];
	    a[i].resize(k[i]);
		for (int j = 0; j < k[i]; j++) {
		    cin >> a[i][j];
		}
		sort(a[i].begin(),a[i].end());
	}
	vector<int> b(m+1);
	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < k[i]; j++) {
			b[a[i][j]]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= m; i++) {
	    if (b[i] == n)
			ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import numpy as np
n=int(input())
a=np.array([0]*4)
for i in range(n):
    s= str(input())
    if s=='AC':
        a[0]+=1
    elif s=='WA':
        a[1]+=1
    elif s=='TLE':
        a[2]+=1
    elif s=='RE':
        a[3]+=1
print('AC x '+str(a[0]))
print('WA x '+str(a[1]))
print('TLE x '+str(a[2]))
print('RE x '+str(a[3]))

Measured memory_bytes: 27160
import Foundation

let input_line: String = readLine()!
let split: [String] = input_line.components(separatedBy: " ") //ブランクで区切られている場合

var A = Int(split[0])!
//String -> Intの型変換はnilが返る可能性があるので、ラップされたOptional<Int>型が返るので強制アンラップ
var B = Int(split[1])!

let value = max(A+B, A-B, A*B)
print(value)

Measured memory_bytes: 14184
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
int N;
string s;
map<string, bool> is_male;

void solve(int begin, int end, bool sex){
    int mid = (begin + end) / 2;
    cout << mid << endl << flush;
    cin >> s;
    if(s == "Vacant"){
        return;
    }
    bool desired_sex;
    if((mid-begin)%2==0){
        desired_sex = sex;
    }else{
        desired_sex = !sex;
    }
    bool answer_in_after = (is_male[s] == desired_sex);
    //cout << (answer_in_after?"true":"false") << endl;
    if(answer_in_after){
        solve(mid, end, is_male[s]);
    }else{
        solve(begin, mid, sex);
    }
}

int main(){
    cin >> N;
    is_male["Male"] = true;
    is_male["Female"] = false;
    cout << 0 << endl << flush;
    cin >> s;
    if(s == "Vacant"){
        return 0;
    }
    solve(0, N, is_male[s]);
}

Measured memory_bytes: 852
#include<stdio.h>
#include<stdlib.h>
int main(){
  long long x,k,d;
  scanf("%lld%lld%lld",&x,&k,&d);
  x=llabs(x);
  if(x/d>k)
    printf("%lld\n",llabs(x-d*k));
  else{
    if((k-x/d)%2==0)
      printf("%lld\n",x-d*llabs(x/d));
    else
      printf("%lld\n",llabs(x-d*(1+x/d)));
  }
  return 0;
}


Measured memory_bytes: 1728
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
vi r;
vi b;
vi g;
lli ss(lli idx, vi& v) {
	lli low = 0;
	lli high = v.size() - 1;
	lli ret = -1;
	while (low <= high) {
		lli mid = low + (high - low) / 2;
		if (v[mid] - idx > 0) {
			ret = mid;
			high = mid - 1;
		} else low = mid + 1;
	}

	return ret;
}
void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void solve() {
	lli n;
	cin >> n;
	string s;
	cin >> s;
	set <lli> rs;
	set <lli> bs;
	set <lli> gs;
	for (lli i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r.pb(i);
			rs.insert(i);
		} else if (s[i] == 'B') {
			b.pb(i);
			bs.insert(i);
		} else {
			g.pb(i);
			gs.insert(i);
		}
	}
	lli ret = 0;
	for (lli i = 0; i < n; i++) {
		for (lli j = i - 1; j >= 0; j--) {
			char ith = s[i];
			char jth = s[j];
			if (ith == jth) continue;
			lli pos = -1;
			//cout << jth << " " << ith << endl;
			int d = i - j;
			if (ith == 'R') {
				if (jth == 'B') {
					pos = ss(i, g);
					if (pos == -1) continue;
					ret += g.size() - pos;
					if (gs.count(i + d)) ret--;
				} else {
					pos = ss(i, b);
					if (pos == -1) continue;
					ret += b.size() - pos;
					if (bs.count(i + d)) ret--;
				}
			} else if (ith == 'B') {
				if (jth == 'G') {

					pos = ss(i, r);
					if (pos == -1) continue;
					ret += r.size() - pos;
					if (rs.count(i + d)) ret--;
				} else {
					pos = ss(i, g);
					if (pos == -1) continue;
					ret += g.size() - pos;
					if (gs.count(i + d)) ret--;
				}
			} else {
				if (jth == 'R') {
					pos = ss(i, b);
					if (pos == -1) continue;
					ret += b.size() - pos;
					if (bs.count(i + d)) ret--;
				} else {
					pos = ss(i, r);
					if (pos == -1) continue;
					ret += r.size() - pos;
					if (rs.count(i + d)) ret--;
				}
			}
			//	cout << pos << " " << endl;
		}
	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 3868
#include <stdio.h>
 
int main(){
	int A, B, C, D;

	scanf("%d %d %d %d", &A, &B, &C, &D);

	if(A <= C) {
		if(B <= C) {
			printf("0");
		}

		else if(B > C && B <= D) {
			printf("%d", B - C);
		}

		else if(B > D) {
			printf("%d", D - C);
		}
	}

	else if(A > C) {
		if(D <= A) {
			printf("0");
		}

		else if(D > A && D <= B) {
			printf("%d", D - A);
		}

		else if(D > B) {
			printf("%d", B - A);
		}
	}
}

Measured memory_bytes: 128
#include<stdio.h>

int A[200],n;
int solve(int,int);
int main(){
    
  int j,i,q,m,ans;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
    
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)==1) printf("yes\n");
    else printf("no\n");
   
    //if(ans==1) printf("yes\n");
    //else if(ans==0) printf("no\n");
   
  }
  return 0;
  
}

int solve(int i,int m){
  int res;
  
  if(m==0) return 1;
  if(i>=n) return 0;
    
  res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}



Measured memory_bytes: 2108
#include<stdio.h>
#define MAX 251

int main(){
  int i,n,A[MAX];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i!=1)printf("parent key = %d, ",A[i/2]);
    if(2*i<=n)printf("left key = %d, ",A[2*i]);
    if(2*i+1<=n)printf("right key = %d, ",A[2*i+1]);
    printf("\n");
  }
  return 0;
}



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

const int maxn = 1e5 + 5;
int A[maxn], B[maxn];

int main() {

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

    for(int i = 0; i < N; i++) {
        if(B[i] > A[i]) A[i+1] -= min(A[i+1], B[i]-A[i]);
        A[i] -= min(A[i], B[i]);
        ans -= A[i];
    }

    printf("%lld", ans-A[N]);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
void pr(int n,char c){
  for(int i=0;i<n;i++){
    cout<<c;
  }
}
int main(){
  int a,b,c,d,r,u;
  cin>>a>>b>>c>>d;
  r=c-a;u=d-b;
  pr(r,'R');
  pr(u,'U');
  pr(r,'L');
  pr(2*u,'D');
  pr(2*r,'R');
  pr(2*u,'U');
  pr(r,'L');
  pr(1,'U');
  pr(1+r,'L');
  pr(1+u,'D');
  pr(1,'R');
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 550
#define LL long long
using namespace std;
int n,nn,m;
int l[N],r[N];
pair<int,int>p[N];
int dp[N][N];
inline int getf(int k,const int mod=m){
	dp[0][0]=1;
	for(int i=1,t=0;i<=nn;++i){
		int id=-p[i].second;
		for(int j=0;j<=i&&j<=k;++j){
			dp[i][j]=0;
			if(id>=n){
				dp[i][j]=1ll*dp[i-1][j]*(r[id]+1-(i-1)+(t-j))%mod;
			}
			else{
				int val=1ll*dp[i-1][j]*(r[id]+1-(nn-id-1+k-j))%mod;
				if(val>=0)dp[i][j]=val;
				if(j) dp[i][j]=(1ll*dp[i-1][j-1]*(l[id]-(j-1+i-1-t))+dp[i][j])%mod;
			}
//			printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
		}
		t+=id<n;
	}
	return dp[nn][k];
}
int main(){
	cin>>n>>m;nn=n<<1;
	const int mod=m;
	for(int i=0;i<nn;++i){
		l[i]=nn;r[i]=0;
		for(int j=0;j<nn;++j)
			if(i*i+j*j>=n*n&&i*i+j*j<=4*n*n)
				l[i]=min(l[i],j),r[i]=max(r[i],j);
//		printf("l:%d r:%d\n",l[i],r[i]);
	}
	for(int i=0;i<n;++i)p[i+1]=make_pair(l[i]-1,-i);
	for(int i=n;i<nn;++i)p[i+1]=make_pair(r[i],-i);
	sort(p+1,p+nn+1);
//	for(int i=1;i<=nn;++i)printf("%d\n",p[i].second);
	int ans=0;
	for(int i=0;i<=n;++i){
//		cout<<i<<" "<<getf(i)<<endl;
		if(i&1)ans+=mod-getf(i);
		else ans+=getf(i);
		if(ans>=mod)ans-=mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4692
# ABC098D

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
s = 0
t = 0
xs = a[0]
ss = a[0]
    
ans = 0
for s in range(n):
    while xs==ss:
        if t<n-1 and xs^a[t+1]==ss+a[t+1]:
            t += 1
            xs ^= a[t]
            ss += a[t]
        else:
            break
    ans += (t-s+1)
    xs ^= a[s]
    ss -= a[s]
print(ans)

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

using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;

ll K, ans[1000005];
int idx = 0;
void dfs(int step, ll num) {
    if (step == 11) {
        return;
    }
    ans[idx++] = num;
    ll last = num % 10, next = num * 10;
    for (int i = last - 1; i <= last + 1; ++i) {
        if (i >= 0 && i <= 9)
            dfs(step + 1, next + i);
    }

}

int main()
{
    fio;
    cin >> K;
    for (int i = 1; i <= 9; ++i) {
        dfs(0, i);
    }
    sort(ans, ans + idx);
    cout << ans[K - 1] << endl;
    cerr << idx << endl;
    cerr << "Time : " << (double) clock() / (double) CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 6400
#include "bits/stdc++.h"

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()


#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>

void print(T x)
{
	std::cout << x << '\n';
}


int main() {
	int N;
	cin >> N;
	int count = 0;
	vector<int> a(N);
	rep(i, N) {
		cin >> a[i];
	}
	sort(all(a));
	int ans = a[N/2]-a[N / 2 - 1];
	printf("%d", ans);
}

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

const int MAX_N = 1000;
typedef long long int ll;

int main() {
  ll x, y, z, k;
  ll a[MAX_N], b[MAX_N], c[MAX_N];

  std::cin >> x >> y >> z >> k;
  for(int i = 0; i < x; ++i) std::cin >> a[i];
  for(int i = 0; i < y; ++i) std::cin >> b[i];
  for(int i = 0; i < z; ++i) std::cin >> c[i];

  std::sort(a, a + x, std::greater<ll>());
  std::sort(b, b + y, std::greater<ll>());
  std::sort(c, c + z, std::greater<ll>());

  std::set<std::tuple<int, int, int>> hist;
  std::priority_queue<std::tuple<ll, int, int, int>> q;

  q.push(std::make_tuple(a[0] + b[0] + c[0], 0, 0, 0));
  hist.insert(std::make_tuple(0, 0, 0));

  for(int t = 0; t < k; ++t) {
    auto top = q.top(); q.pop();

    std::cout << std::get<0>(top) << std::endl;

    int h, i, j;
    h = std::get<1>(top);
    i = std::get<2>(top);
    j = std::get<3>(top);

    if(h + 1 < x && ! hist.count(std::make_tuple(h + 1, i, j))) {
      q.push(std::make_tuple(a[h + 1] + b[i] + c[j], h + 1, i, j));
      hist.insert(std::make_tuple(h + 1, i, j));
    }
    if(i + 1 < y && ! hist.count(std::make_tuple(h, i + 1, j))) {
      q.push(std::make_tuple(a[h] + b[i + 1] + c[j], h, i + 1, j));
      hist.insert(std::make_tuple(h, i + 1, j));
    }
    if(j + 1 < z && ! hist.count(std::make_tuple(h, i, j + 1))) {
      q.push(std::make_tuple(a[h] + b[i] + c[j + 1], h, i, j + 1));
      hist.insert(std::make_tuple(h, i, j + 1));
    }
  }

}

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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

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

int n, u, v;
std::vector<int> g[N];
int dp[2][N];

int go(int u, int par, int col){
	int &ans = dp[col][u];
	if(~ans)
		return ans;
	ans = 1;

	for(int v : g[u]) if(v != par){
		if(col == 0){
			ans = (ans * go(v, u, !col)) % mod;
		}
		else{
			ans = (ans * (go(v, u, !col) + go(v, u, col))) % mod;
		}
	}
	return ans;
}

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);  
	
	memset(dp, -1, sizeof(dp));
	cin >> n;
	FOR(i,2,n){
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	int ans = go(1,-1,0) + go(1,-1,1);
	ans %= mod;
	cout << ans;
}


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

using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int N = 1000005, MOD = 1000000007;
int f[N], finv[N], act[N];

inline int mul(int a, int b) {
    return (ll)a * b % MOD;
}

void precalc() {
    f[0] = 1;
    for (int i = 1; i < N; i++) {
        f[i] = mul(f[i - 1], i);
    }
    finv[0] = finv[1] = 1;
    for (int i = 2; i < N; i++) {
        finv[i] = (MOD - mul(MOD / i, finv[MOD % i])) % MOD;
    }
    for (int i = 2; i < N; i++) {
        finv[i] = mul(finv[i - 1], finv[i]);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(cout.fixed);
    cout.precision(20);
    precalc();
    int n;
    cin >> n;
    for (int k = (n + 1) / 2; k < n; k++) {
        act[k] = mul(mul(f[k - 1], f[k]), finv[2 * k - n]);
    }
    int res = 0;
    for (int k = (n + 1) / 2; k < n; k++) {
        res = (res + mul(k, act[k] - act[k - 1] + MOD)) % MOD;
    }
    cout << res << "\n";
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    
    vector<int> v;
    repeat (i, 3) {
        int t; cin >> t;
        v.push_back(t);
    }
    sort(v.begin(), v.end());
    
    int a, b, c;
    a = v[0]; b = v[1]; c = v[2];
    
    int ans = 0;
    ans += (c - a) / 2;
    ans += (c - b) / 2;
    
    bool x, y;
    x = ( (c-a) % 2 == 0 );
    y = ( (c-b) % 2 == 0 );
    
    if ( x and y ) {
    }
    else if ( (not x) and y ) {
        ans += 2;
    }
    else if ( x and (not y) ) {
        ans += 2;
    }
    else {
        ans += 1;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
s = int(input())
count = 0
if s == 2 or s == 1:
    print(4)
else:
    while s != 4:
        count += 1
        if s % 2 == 1:
            s = 3 * s + 1
        else:
            s = s // 2
    print(count + 4)

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

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  i64 maxlen = 0;
  REP(i, N) {
    cin >> A[i];
    maxlen = max(maxlen, A[i]);
  }
  sort(A.begin(), A.end());
  auto is_ok = [&](double x) -> bool {
    assert(x > 0.0);
    i64 mincut = 0;
    REP(i, N) {
      if (A[i] <= x + 1e-8) {
        continue;
      }
      i64 c = ceil(A[i] / x) + 1e-8;
      c -= 1;
      mincut += c;
      if (mincut > K) return false;
    }
    return true;
  };
  double ng = 0, ok = maxlen;
  REP(iter, 200) {
    double mid = (ok + ng) / 2.0;
    if (is_ok(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  {
    i64 ans = ceil(ok) + 0.001;
    cout << ans << endl;
  }
}


Measured memory_bytes: 4688
def calc(x1, y1, x2, y2, x3, y3):
    point_list = [x1, y1, x2, y2, x3, y3]
    point_list = [str(i) for i in point_list]
    print(" ".join(point_list))

s = int(input())
inf = 10 ** 9
if s >= inf:
    x1 = 0
    y1 = 0
    x2 = inf
    y2 = 1
    y3 = (s // inf) + 1 
    x3 = inf - (s % inf)
    if (abs(y3) <= inf) & (abs(x3) <= inf):
        calc(x1, y1, x2, y2, x3, y3)
    else:
        x1 = 0
        y1 = 0
        x2 = inf
        y2 = 1
        y3 = s // inf
        x3 = s % inf
        calc(x1, y1, x2, y2, x3, y3)
else:
    x1 = 0
    y1 = 0
    x2 = inf
    y2 = 1
    y3 = 0
    x3 = s
    calc(x1, y1, x2, y2, x3, y3)



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

using namespace std;

typedef long long  ll;

int Rec(int idx, vector<bool> &used, vector<int> &f_no,
        const vector<vector<int>> &s_idx, const vector<bool> &is_head) {

    if (idx == -1) {
        const int n = s_idx.size();
        int sum = 0, ans = 0;

        for (int i = 0; i < n; ++i) {
            int num = 0;
            for (int j = 0; j < s_idx[i].size(); ++j) {
                num *= 10;
                num += f_no[s_idx[i][j]];
            }

            if (i == n - 1)
                ans = num;
            else
                sum += num;
        }

        return (ans == sum) ? 1 : 0;
    }

    int res = 0;
    for (int d = 0; d < 10; ++d) {
        if (d == 0 && !is_head[idx])
            continue;
        if (!used[d]) {
            f_no[idx] = d;
            used[d] = true;
            res += Rec(idx - 1, used, f_no, s_idx, is_head);
            used[d] = false;
        }
    }

    return res;
}


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

    int n;

    while (cin >> n, n) {
        vector<string> s(n);
        vector<vector<int>> s_idx(n);
        vector<char> set_c;

        for (int i = 0; i < n; ++i) {
            cin >> s[i];
            s_idx[i].resize(s[i].size());
            for (auto c : s[i])
                set_c.emplace_back(c);
        }

        sort(set_c.begin(), set_c.end());
        set_c.erase(unique(set_c.begin(), set_c.end()), set_c.end());

        for (int i = 0; i < n; ++i)
            for (int j = 0; j < s[i].size(); ++j)
                for (int k = 0; k < set_c.size(); ++k)
                    if (s[i][j] == set_c[k]) {
                        s_idx[i][j] = k;
                        break;
                    }

        vector<bool> used(10, false);
        vector<int> f_no(set_c.size(), -1);
        vector<bool> is_head(set_c.size(), true);

        for (int i = 0; i < set_c.size(); ++i)
            for (int j = 0; j < s.size(); ++j)
                if (s[j].size() != 1 && set_c[i] == s[j][0])
                    is_head[i] = false;

        cout << Rec(set_c.size() - 1, used, f_no, s_idx, is_head) << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  if(n<100) cout<<min(n,(int)9)<<endl;
  else if(n<10000) cout<<min(9+(n-99),(int)909)<<endl;
  else cout<<min(9+900+(n-9999),(int)90909)<<endl;
  //cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main(){
    int N, T, A;
    cin >> N >> T >> A;
    int H[N];
    int res = 0;
    int cc = numeric_limits<int>::max();

    for (int i = 1; i <= N; i++){
        cin >> H[i];
        int d = (T * 1000 - H[i] * 6) - A * 1000;
        if(d < 0) d = -d;
        if(cc > d)
            cc = d, res = i;
    }

    cout << res << endl;
}

Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())

a = tx - sx
b = ty - sy

kei = ''
for i in range(a):
    kei = kei + 'R'
    
for i in range(b):
    kei = kei + 'U'
    
for i in range(a):
    kei = kei + 'L'
    
for i in range(b+1):
    kei = kei + 'D'
    
for i in range(a+1):
    kei = kei + 'R'
    
for i in range(b+1):
    kei = kei + 'U'
    
kei = kei + 'LU'

for i in range(a+1):
    kei = kei + 'L'
    
for i in range(b+1):
    kei = kei + 'D'
    
kei = kei + 'R'

print(kei)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
bool constSort(const lli a, const lli b) {
  return b < a;
}

int main() {
  lli n, k;
  vector<lli> h;
  cin >> n >> k;
  while (cin >> n) h.push_back(n);
  sort(h.begin(), h.end(), constSort);
  lli ans = 0;
  for (lli i = k; i < h.size(); i++) {
    ans += h[i];
  }
  cout << ans << '\n';
  return 0;}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define coYes cout << "Yes" << endl
#define coYES cout << "YES" << endl
#define coyes cout << "yes" << endl
#define coNo cout << "No" << endl
#define coNO cout << "NO" << endl
#define cono cout << "no" << endl
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){ //最大公約数
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int n,c=0;
    cin >> n;
    vector<int> d(n);
    rep0(i,n)
        cin >> d[i];
    sort(d.begin(),d.end());
    while(d[n/2-1]<d[n/2]){
        c++;
        d[n/2-1]++;
    }
    cout << c << endl;
}

Measured memory_bytes: 3752
#include <iostream>
#include <limits.h>
using namespace std;
 
int main()
{
    ios::sync_with_stdio(false);
    int n, r;
    int min=INT_MAX, ans=INT_MIN;
     
    cin >> n;
    for(int t=1; t<=n; t++) {
        cin >> r;
        if(r-min > ans) ans = r-min;
        if(r < min) min = r;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  for (int i = 1; ; i++) {
    if (x <= i*(i+1)/2) {
      cout << i << '\n';
      return 0;
    }
  }
}

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

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

template<typename T> istream &operator >> (istream &is, vector<T> &vec){ for (T& v : vec) is >> v; return is; }
template<typename T> ostream &operator << (ostream &os, const vector<T> &vec){ for (auto v : vec) os << v << " "; return os; }

deque<int> G[2010];

int main(){
    int N,X,Y;
    cin >> N >> X >> Y;
    
    rep(i,1,N){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[X].push_back(Y);
    G[Y].push_back(X);
    
    // rep(i,1,N+1){
    //     cout << i << " : ";
    //     for(auto j : G[i]){
    //         cout << j << " ";
    //     }
    //     cout << endl;
    // }

    vector<int> K(N+1,0);

    rep(i,1,N+1){
        // initialize
        vector<int> dist(N+1,-1);
        queue<int> que;
        dist[i] = 0;
        que.push(i);

        while(!que.empty()){
            int v = que.front();
            que.pop();
            for(int nv : G[v]){
                if(dist[nv]!=-1) continue;
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }

        rep(j,i,N+1){
            K[dist[j]] += 1;
        }
    }

    rep(i,1,N){
        cout << K[i] << " " << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>

using namespace std;

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

int main() {
  int n, c = 0;
  cin >> n;
  rep (i, n) {
    string str;
    int k;
    cin >> str >> k;
    if (str == "(") c += k;
    else c -= k;
    if (c < 0) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << (c ? "NO" : "YES") << endl;
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int strrrcmp(int *,int *);
int main()
{
    int a,b;
    cin >> a >> b;
    int aa[100],bb[100];
    int i;
    for(i=0;i<b;i++)
        aa[i]=a;
        aa[i]='\0';
    for(i=0;i<a;i++)
        bb[i]=b;
        bb[i]='\0';
     if(strrrcmp(aa,bb)<0)
        {
                for(i=0;i<b;i++)
        cout << aa[i];
        }
     else
            for(i=0;i<a;i++)
        cout << bb[i];
    return 0;
}
int strrrcmp(int *a,int *b)
{
    for(int i=0;a[i]!='\0'&&b[i]!='\0';i++)
    {
        if(a[i]<b[i])
        return -1;
        else if(a[i]>b[i])
        return 1;
        else
        continue;
    }
    return 0;
}


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

int n, m, q;
int a[50], b[50], c[50], d[50];
int ans;

void dfs(vector<int> A) {
    if (A.size() == n + 1) {
        int sum = 0;
        rep(i, q) if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
        ans = max(ans, sum);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> n >> m >> q;
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    dfs(vector<int>(1, 1));

    cout << ans << endl;
    return 0;
}


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

signed main()
{
  string s, t;
  cin >> s >> t;
  bool f = true;
  for (int i = 0; i < s.length(); i++)
    f &= s[i] == t[i];
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3628
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        
        int[] distances = new int[N];
        for(int i = 0; i < N; i++){
            int x = sc.nextInt();
            distances[i] = Math.abs(X - x);
        }
        
        int ans = distances[0];
        for(int i = 1; i < N; i++){
            ans = gcd(ans, distances[i]);
        }
        
        System.out.println(ans);
    }
    
    static int gcd(int a, int b){
        if( b == 0 ) return a;
        return gcd(b, a%b);
    }
}


Measured memory_bytes: 50204
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

Q, H, S, D = list(map(int, sys.stdin.buffer.readline().split()))
N = int(sys.stdin.buffer.readline())

H = min(Q * 2, H)
S = min(H * 2, S)
D = min(S * 2, D)
ans = N // 2 * D + N % 2 * S
print(ans)


Measured memory_bytes: 23128