akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N;
    cin>>N;
    int K;
    cin>>K;
    vector<int>arr(N);
    for(int i=0;i<N;i++)
        cin>>arr[i];
    vector<int>ans(N,1e9+5);
    ans[0]=0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<=i+K;j++){
            if(j<N){
                ans[j]=min(ans[j],ans[i]+abs(arr[i]-arr[j]));
            }
        }
    }
    cout<<ans[N-1];
	return 0;
}

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

using namespace std;

const int MX = 200000;

char s[MX + 1];

int main() {
	ignore = scanf("%s", s);
	
	int w = 0;
	long long sw = 0, sf = 0;
	for (int i = 0; s[i] != 0; i++) {
		if (s[i] == 'W') {
			sw += i;
			sf += w;
			w++;
		}
	}
	
	printf("%lld\n", sw - sf);
	
	return 0;
}


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

vector<int> ans;
vector<int> to[200005];
void dfs(int x,int p=-1){
  for(int i : to[x]){
    if(p == i) continue;
    ans[i] += ans[x];
    dfs(i,x);
  }
}

signed main(){
  int n,q;
  cin>>n>>q;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  
  ans.resize(n);
  rep(i,q){
    int p,x;
    cin>>p>>x;
    p--;
    ans[p] += x;
  }
  dfs(0);
  rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 24320
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int d = INF, ans = 0;
    for(int i = 0; i <= 10000; i++)
    {
        string s = to_string(i), t = to_string(i);
        reverse(t.begin(), t.end());
        if(s == t)
        {
            if(abs(stoi(s) - n) < d)
            {
                d = abs(stoi(s) - n);
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3272
#include <iostream>
#include <cmath>
#include <iomanip>
#include <utility>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#define ll long long
         
using namespace std;
     
long long gcd(int x, int y){
     if ( x == 0 ) return y;
     
     return gcd(y%x, x);
}
     
long long lcm(int x, int y){
     if ( y == 0 ){
          return x;
     }
     
     return x*y/gcd(x, y);
}
     
int min(int a, int b){
     return a > b ? b : a;
}
     
int max(int a, int b){
     return a > b ? a : b;
}

ll stepen(ll n, ll a){
     ll p = n;
     for (int i=0;i<a-1;i++){
          p*=n;
     }

     return p;
}

int main()
{
     cin.sync_with_stdio( false );
     ll x;
     cin>>x;

     for (int i=-120;i<=120;i++){
          for (int j=-120;j<=120;j++){
               //cout<<i<<" "<<j<<" "<<stepen(i, 5)<<" "<<stepen(j, 5)<<endl;
               if ( stepen(i, 5) - stepen(j, 5) == x || stepen(j, 5) - stepen(i, 5) == x ){
                    cout<<max(i, j)<<" "<<min(i, j)<<endl;
                    return 0;
               }
          }
     }
}

Measured memory_bytes: 3640
#include <cstdio>
#include <set>

int main()
{
    int n, q;
    scanf("%d", &n);
    char s[500001];
    scanf("%s", s);

    std::set<int> st[26];

    for (int i = 0; i < n; i++)
    {
        st[s[i] - 'a'].insert(i + 1);
    }
    for (int k = 0; k < 26; k++)
    {
        st[k].insert(1000000);
    }

    scanf("%d", &q);

    char ss[50001];
    ss[n] = '\0';

    for (int j = 0; j < q; j++)
    {
        int tmp;
        scanf("%d", &tmp);
        if (tmp == 1)
        {
            int i;
            char c;
            scanf("%d %c", &i, &c);
            for (int k = 0; k < 26; k++)
            {
                if (st[k].find(i) != st[k].end())
                {
                    st[k].erase(i);
                    break;
                }
            }
            st[c - 'a'].insert(i);

            // for (int k = 0; k < 26; k++)
            // {
            //     std::set<int>::iterator it = st[k].begin();
            //     while (*it < 1000000)
            //     {
            //         ss[(*it++) - 1] = 'a' + k;
            //     }
            // }
            // printf("%s\n", ss);
        }
        else
        {
            int l, r, cnt = 0;
            scanf("%d %d", &l, &r);
            for (int k = 0; k < 26; k++)
            {
                if (*st[k].lower_bound(l) <= r)
                {
                    cnt++;
                }
            }
            printf("%d\n", cnt);
        }
    }

    return 0;
}

Measured memory_bytes: 24192
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let v = read_vec::<u64>();
    if (v[0]*100 + v[1]*10 +v[2]) % 4 == 0{
        println!("YES");
    } else{
        println!("NO");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 10;
int a[maxn], b[maxn], n;
ll fact[maxn];

bool useda[maxn], usedb[maxn];

int main() {
	cin>>n;

	fact[0] = 1LL;
	for(int i=1;i<maxn;i++) {
		fact[i] = fact[i-1] * i;
	}

	ll order_a = 0LL, order_b = 0LL;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		
		int cnt = 1;
		for(int j=1;j<=n;j++) {
			if(j < a[i] && !useda[j]) cnt++;
		}

		order_a += (cnt - 1) * fact[n - i];
		useda[a[i]] = true;

	}
	
	for(int i=1;i<=n;i++) {
		cin>>b[i];
		
		int cnt = 1;
		for(int j=1;j<=n;j++) {
			if(j < b[i] && !usedb[j]) cnt++;
		}

		order_b += (cnt - 1) * fact[n - i];
		usedb[b[i]] = true;

	}
	cout<<abs(order_b - order_a)<<"\n";
}

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

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

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

	string S=in<string>(),T=in<string>();
	vvll C(26);
	int N=S.size(),K=T.size();
	REP(i,N) C[S[i]-'a'].push_back(i+1);
	REP(i,K){
		if(C[T[i]-'a'].empty()){
			out(-1);
			return 0;
		}
	}
	ll A=0,P=1;
	REP(i,K){
		ll Q=T[i]-'a';
		auto res = lower_bound(ALL(C[Q]),P);
		if(res!=C[Q].end()){
			A += (*res)-P+1;
			P = *res+1;
		}
		else{
			A += N-P+1;
			A += C[Q].front();
			P = C[Q].front()+1;
		}
	}

	out(A);
	return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long 
#define ld long double
#define MOD 1000000007
#define mod9 1000000009
#define mod 1000003
#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define test ll t;cin>>t;while(t--)
#define bi begin()
#define ei end()
#define fi first 
#define se second  
#define forn(a,b) for(ll i=a;i<b;i++)
#define sz(s) s.size()     
#define pi 3.14159265358979323846
#define sp(x) cout<<fixed<<setprecision(x)

int main()
{
	 ll a,b,n;
	 cin>>a>>b>>n;
	 cout<<floor((a*min(b-1,n))/b)-a*(floor((min(n,b-1))/b))<<endl;
	 return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A, B;
    cin >> A >> B;
    if (A*B % 2 == 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include <algorithm>

#define EPS 1e-10

using namespace std;

int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}

	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}


int main(){
	double x1,x2,x3,x4,y1,y2,y3,y4;
	int q;
	scanf("%d",&q);

	for(int i=0;i<q;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);

		if(func(x1,y1,x2,y2,x3,y3)*func(x1,y1,x2,y2,x4,y4) <= 0 &&
				func(x3,y3,x4,y4,x1,y1) * func(x3,y3,x4,y4,x2,y2) <= 0){
			printf("1\n");
		}else{
			printf("0\n");
		}
	}

    return 0;
}



Measured memory_bytes: 2752
import java.util.*;
public class Main{
    
    public static void main(String [] args){
   
     Scanner sn = new Scanner(System.in);
    String a = sn.next();
     System.out.println( a.substring(0,1)+(a.length()-2)+""+a.substring(a.length()-1,a.length()));
   }
}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);
const long long MOD = 1000000007;

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {
    ll a;
    ll p[200010];
    string s;

    REP(i, 5){
        cin >> a;
        if (a == 0){
            cout << i+1 << endl;
        }
    }
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(3);
  a.at(0) = n / 100;
  a.at(1) = (n - n / 100 * 100) / 10;
  a.at(2) = n % 10;
  vector<int> b(3);
  b = {a.at(0), a.at(1), a.at(2)};
  rep(i, 3) {
    if (a.at(i) == 9) b.at(i) = 1;
    else if (a.at(i) == 1) b.at(i) = 9;
  }
  cout << b.at(0) << b.at(1) << b.at(2) << endl;
}


Measured memory_bytes: 256
// 2020-09-20 19:18:45
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
#include <atcoder/twosat>
// #include <atcoder/all>
using namespace atcoder;

// clang-format on
void answer() {
  int n, d;
  cin >> n >> d;
  two_sat G(n);
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  rep(i, n - 1) REP(j, i + 1, n) {
    if (abs(x[i] - x[j]) < d) {
      G.add_clause(i, false, j, false);
    }
    if (abs(x[i] - y[j]) < d) {
      G.add_clause(i, false, j, true);
    }
    if (abs(y[i] - x[j]) < d) {
      G.add_clause(i, true, j, false);
    }
    if (abs(y[i] - y[j]) < d) {
      G.add_clause(i, true, j, true);
    }
  }
  if (!G.satisfiable()) {
    cout << "No" << '\n';
    return;
  }
  cout << "Yes" << '\n';
  auto ans = G.answer();
  rep(i, n) cout << (ans[i] ? x[i] : y[i]) << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3748
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {
	String S;
	boolean result = false;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		S = in.readLine();

	}

	boolean isKaibun(String s) {
		int n = s.length() / 2;
		for (int i = 0; i < n; ++i) {
			if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
				return false;
			}
		}
		return true;
	}

	void calc() {
		result = isKaibun(S);
		if (!result) {
			return;
		}
		String subStr1 = S.substring(0, (S.length() - 1) / 2);
		result = isKaibun(subStr1);
		if (!result) {
			return;
		}
		result = isKaibun(S.substring((S.length() + 3) / 2 - 1, S.length()));

	}

	void showResult() {
		System.out.println((result ? "Yes" : "No"));
	}

}


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

//#define int long long

using namespace std;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    bool flag = false;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x % 2 == 1) flag = true;
    }
    if (flag) cout << "first\n";
    else cout << "second\n";
}
/*

 */


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

vl v,a,b,c,d;
ll n,m,q;
ll ans = 0;
//重複順列
//参考URL https://minus9d.hatenablog.com/entry/20130706/1373104487
void dfs(int i, const int size, const int range_start, const int range_end)
{
    if (i == size) {
        ll res = 0;
        rep(j,q)if(v[b[j]] - v[a[j]] == c[j])res+= d[j];
        ans = max(ans,res);
    }
    else{
        for(int j = range_start; j <= range_end; ++j){
            v[i] = j;
            dfs(i + 1, size,j, range_end);
        }
    }
}

signed main()
{   
    gearup;
    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    rep(i,q){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;b[i]--;
    }
    v.resize(n);
    dfs(0,n,1,m);
    out(ans);
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const int N=2e3+5;
int n,w[N],b[N],x;
int dp[N][N],cw[N][N],cb[N][N];
int main(){
	memset(cw,0,sizeof(cw));
	memset(cb,0,sizeof(cb));
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++){
		char op[2];
		scanf("%s%d",op,&x);
		if(op[0]=='W')
			w[x]=i;
		else
			b[x]=i;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++)
			if(w[i]<w[j])
				cw[i][0]++;
		for(int j=1;j<=n;j++){
			cw[i][j]=cw[i][j-1];
			if(w[i]<b[j])
				cw[i][j]++;	
		}
	}	
	for(int i=1;i<=n;i++){
		for(int j=1;j<i;j++)	
			if(b[i]<b[j])
				cb[0][i]++;
		for(int j=1;j<=n;j++){
			cb[j][i]=cb[j-1][i];
			if(b[i]<w[j])
				cb[j][i]++;
		}
	}
	int c1=0,c2=0;
	for(int i=1;i<=n;i++){
		c1+=cw[i][0],c2+=cb[0][i];
		dp[i][0]=c1,dp[0][i]=c2;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dp[i][j]=min(dp[i-1][j]+cw[i][j],dp[i][j-1]+cb[i][j]);	
	cout<<dp[n][n]<<endl;
	return 0;
}


Measured memory_bytes: 47360
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 79660
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
// using ll = long long;
// using vi = vector<int>;
// using vvi = vector<vi>;
// using vl = vector<long long>;
// using vvl = vector<vl>;
// using vs = vector<string>;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

int kaijo (int a, int result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo(a-1, result * a);
  }
}

int kaijo(int a) {
  return kaijo(a,1);
}

ll kaijo_ll (ll a, ll result) {
  if (a == 0) {
    return result;
  } else {
    return kaijo_ll(a-1, result * a);
  }
}

ll kaijo_ll(ll a) {
  return kaijo_ll(a,1);
}

int main () {
  string s;
  int n,m,a,b,c;
  cin >> a >> s;
  if(a < 3200) {
    s = "red";
  }
  cout << s << endl;
}


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


int main(){
  int n,k;
  cin >> n >> k;
  int ans=0;
  rep(i,n){
    int x;
    cin >> x;
    ans+=2*min(x,k-x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define testcase int tc;cin>>tc;while(tc--)
#define all(x) x.begin(),x.end()
#define allR(x) x.rbegin(),x.rend()

int main()
{

    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
    ll k = __gcd(n,x);
    cout<<3*(n-k)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n;
	int a[15][15];

	while(1){
		scanf("%d", &n);
		if(n == 0) break;

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

		int x = n/2;
		int y = n/2 + 1;
		a[x][y] = 1;
		for(int i=2; i<=n*n; i++){
			x++;
			y++;
			while(1){
				if(x < n && y < n && x >= 0 && a[x][y] == 0){
					a[x][y] = i;
					break;
				}else{
					if(x >= n){
						x = 0;
					}else if(y >= n){
						y = 0;
					}else if(x < 0){
						x = n-1;
					}else{
						x--;
						y++;
					}
				}
			}
		}

		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				printf("%4d", a[j][i]);
			}
			puts("");
		}
	}

	return 0;
}

Measured memory_bytes: 0
import sys

sys.setrecursionlimit(10 ** 6)


def dfs(v, p, aaa):
    if len(links[v]) == 1:
        return aaa[v]

    children = []
    for u in links[v]:
        if u == p:
            continue
        result = dfs(u, v, aaa)
        if result == -1:
            return -1
        children.append(result)

    if len(children) == 1:
        if aaa[v] != children[0]:
            return -1
        return children[0]

    c_sum = sum(children)
    c_max = max(children)
    o_max = c_sum - c_max

    if o_max >= c_max:
        max_pairs = c_sum // 2
    else:
        max_pairs = o_max
    min_remain = c_sum - max_pairs
    if not min_remain <= aaa[v] <= c_sum:
        return -1

    return aaa[v] * 2 - c_sum


def solve(n, aaa, links):
    if n == 2:
        return aaa[0] == aaa[1]
    # 葉でない頂点探し
    s = 0
    while len(links[s]) == 1:
        s += 1
    return dfs(s, -1, aaa) == 0


n = int(input())
aaa = list(map(int, input().split()))
links = [set() for _ in range(n)]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)

print('YES' if solve(n, aaa, links) else 'NO')


Measured memory_bytes: 117928
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  init();
  ll N;
  cin >> N;
  map<ll, ll> m;
  rep(i, N) {
    ll a;
    cin >> a;
    if (m[a] == 0) {
      m[a]++;
    } else {
      m.erase(a);
    }
  }
  COUT(m.size());
  return 0;
}

Measured memory_bytes: 9820
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int A = int.Parse(s[0]);
            int B = int.Parse(s[1]);
            int K = int.Parse(s[2]);
            int res = 0;
            for (int i = 100; i > 0; i--)
            {
                if ((A % i) == 0 && (B % i) == 0)
                {
                    if (K == 1) { res = i; break; }
                    K--;
                }
            }
            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 30;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vi a(n), b(n), c(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[n + 1][401][401];
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= 400; ++j) {
            for (int k = 0; k <= 400; ++k) {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 400; ++j) {
            for (int k = 0; k < 400; ++k) {
                chmin(dp[i][j][k], dp[i - 1][j][k]);
                if (j - a[i - 1] >= 0 && k - b[i - 1] >= 0)
                    chmin(dp[i][j][k], dp[i - 1][j - a[i - 1]][k - b[i - 1]] + c[i - 1]);
            }
        }
    }
    int ret = INF;
    int i = 1;
    while (i * ma < 401 && i * mb < 401) {
        chmin(ret, dp[n][i * ma][i * mb]);
        ++i;
    }
    if (ret == INF)
        cout << -1 << "\n";
    else
        cout << ret << "\n";

    return 0;
}

Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N;
  cin >> N;
  vector<int> moneys = {1};
  int n = 1;
  while (pow(6, n) <= N)
  {
    moneys.push_back(pow(6, n));
    n++;
  }
  n = 1;
  while (pow(9, n) <= N)
  {
    moneys.push_back(pow(9, n));
    n++;
  }
  vector<int> dp(N + 1, -1);
  dp[0] = 0;
  int ans = 0;
  while (dp[N] == -1)
  {
    vector<int> pre_dp = dp;

    rep(i, N + 1)
    {
      if (pre_dp[i] == -1)
        continue;
      rep(j, moneys.size())
      {
        int money = moneys[j] + i;
        if (money > N)
          continue;
        dp[money] = ans;
      }
    }
    ans++;
  }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <string>
using namespace std;
using lint = long long int;
using lond = long double;
using ll = long long;
#define rep(i,n) for (lint i = 0; i < (n); ++i)
//ans

int main (){
	string s;
	cin >> s; 
	lint ans = 0;
	lint i = 0;
	lint n = s.size();
	if (s == "0"){
		cout << "Yes" << endl;
		return 0;
	}
	s.push_back('a');
	while (s[i] != 'a'){
		ans += s[i]-'0';
		if (ans != 0 && fmod(ans,9) == 0){
			if (s[i+1] == 'a'){
				cout << "Yes" << endl;
				return 0;
			}
			ans = 0;
			i++;
			s = s.substr(i);
			i = 0;
		}
		else i++;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 4096
#-*- coding:utf-8 -*-

N = int(input())
W = [int(_) for _ in input().split()]

sm = sum(W)
acc = [0]*N
s = 0
for i in range(N):
    acc[i] = s + W[i]
    s += W[i]

mn = 100
for i in range(N):
    s = abs(acc[i] - (sm-acc[i]))
    mn = min(mn, s)

print(mn)


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

int main() {
    int N;
    long long X;
    cin >> N >> X;
    vector<long long> x(N);
    vector<long long> S(N+1, 0);
    for(int i=0; i<N; ++i) {
        cin >> x[i];
        S[i + 1] = S[i] + x[i];
    }

    long long res = -1;
    for(int k=1; k<=N; ++k) {
        long long tmp = (N + k) * X;
        for(int j=0; ; ++j) {
            if(N % k == 0 && j >= N / k) break;
            if(N % k != 0 && j > N / k) break;
            tmp += (2 * (j == 0 ? 2 : j+1) + 1) * (S[N - k * j] - S[max(N - k * (j + 1), 0)]);
        }
        if(tmp < 0) continue;
        if(res == -1) res = tmp;
        else res = min(res, tmp);
    }

    cout << res << endl;
}

Measured memory_bytes: 3328
# B
n = int(input()) 
s = [str(input()) for i in range(n)] 
m = int(input()) 
t = [str(input()) for i in range(m)]
ans = []
for string in list(set(s)):
    ans.append(s.count(string) - t.count(string))
if max(ans) < 0:
    print(0)
else:
    print(max(ans))

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

int main()
{
    int n;
    cin>> n;
    int a[n];
    int co=0,ma=0;
    for(int i=0;i<n;++i){
        cin >> a[i];
        if(a[i]==1)co++;
        else {
            ma=max(ma,co);
            co=0;
        }
    }
    cout << max(ma+1,co+1)<<endl;
    return 0;
}



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

int main() {
    int D,G,i,j,k,r=1001,s,q,tG;
    cin >> D >> G;
    vector<pair<int,int>> pc(D);

    for(i=0; i<D; i++)
        cin >> pc.at(i).first >> pc.at(i).second;

    for(i=0; i<(1<<D); i++) {
        s=0, q=0, tG=G;
        for(j=D-1; j>=0; j--)
            if(1<<j & i) {
                int p=pc.at(j).first, c=pc.at(j).second;
                if((j+1)*100*p+c >= tG) {
                    for(k=0; k<p; k++) {
                        tG -= (j+1)*100;
                        if(k == p-1)
                            tG -= c;
                        q++;
                        if(tG<=0)
                            break;
                    }
                } else {
                    tG -= (j+1)*100*p+c;
                    q += p;
                }
            }
        if(tG <= 0)
            r = min(r, q);
    }

    cout << r << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> S(n);
    int s;
    for (int i=0; i<n; ++i) {
        cin >> s;
        S[i] = s;
    }
    int q;
    cin >> q;
    int t;
    int cnt = 0;
    for (int i=0; i<q; ++i) {
        cin >> t;
        for (auto&& i: S) {
            if (i == t) {
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3076
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int r;
  scanf("%d",&r);
  if(r<1200){
    printf("ABC\n");
  } else if(r<2800){
    printf("ARC\n");
  } else {
    printf("AGC\n");
  }
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

int main(){
    int n;cin >> n;
    for (int i = 0; i < 20; i++) {
        if(n==(1<<i)){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    if(n%2==1){
        for (int i = 2; i <= n; i++) {
            cout << 1 << " " << i << endl;
        }
        for (int i = 2; i <= n; i++) {
            if(i%2==0) cout << n+i << " " << i+1 << endl;
            else cout << n+i << " " << i-1 << endl;
        }
        cout << 1+n << " " << n+2 << endl;
    }
    else{
        int t=n,u=0;
        for (int i = 30; i >=0 ; i--) {
            if(n&(1<<i)){
                t-=1<<i;
                u=1<<i;
                break;
            }
        }
        for (int i = 2; i <= n-1; i++) {
            cout << 1 << " " << i << endl;
        }
        for (int i = 2; i <= n-1; i++) {
            if(i%2==0) cout << n+i << " " << i+1 << endl;
            else cout << n+i << " " << i-1 << endl;
        }
        cout << n+1 << " " << 2+n << endl;
        cout << n << " " << (t^1) << endl;
        cout << n+n << " " << u << endl;
    }
    return 0;
}


Measured memory_bytes: 2304
N = int(input())

if N < 2:
  print(1)
elif N < 4:
  print(2)
elif N < 8:
  print(4)
elif N < 16:
  print(8)
elif N < 32:
  print(16)
elif N < 64:
  print(32)
elif N < 128:
  print(64)
  

Measured memory_bytes: 9084
import heapq
n,m = map(int, input().split())
a = list(map(lambda x: - int(x), input().split()))
heapq.heapify(a)
ans = 0


for i in range(m):
  most_expensive = -heapq.heappop(a)
  most_expensive //= 2
  heapq.heappush(a, -most_expensive)

print(-sum(a))



Measured memory_bytes: 14252
n = int(input())

r = [ int(input()) for _ in range(n) ]
# print(r)

v_max = r[1]
v_min = r[0]
profit_best = v_max - v_min

for j in range(2,n):
    v_max = r[j]
    v_min = min(v_min,r[j-1])
    profit_tmp = v_max - v_min
    profit_best = max(profit_best,profit_tmp)

print(profit_best)


Measured memory_bytes: 13592
#include <bits/stdc++.h>
using namespace std;
 
int main(){
int x;
cin >> x;
int sum;
sum=0;
int i,k;
for ( i=1;;i++){
sum=sum+i;
k=x-sum;
if (k<=0){
break;
}
}
cout << i << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, p, ev, od int
	fmt.Scan(&n, &p)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a%2 == 0 {
			ev++
		} else {
			od++
		}
	}
	if p == 1 {
		if od == 0 {
			fmt.Println(0)
			return
		}
	}
	fmt.Println(ka(od-1) * ka(ev))
}

func ka(a int) int {
	v := 1
	for i := 0; i < a; i++ {
		v *= 2
	}
	return v
}


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

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<bool> > adj(n, vector<bool>(n, false));
    for(int i=0; i<m; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        adj[a][b] = adj[b][a] = true;
    }
    vector<int> p(n);
    for(int i=0; i<n; i++){
        p[i] = i;
    }
    int ans = 0;
    do{
        bool success = true;
        for(int i=0; i<n-1; i++){
            if(!adj[p[i]][p[i+1]]){
                success = false;
                break;
            }
        }
        if(success){
            ans++;
        }
    }while(next_permutation(p.begin()+1, p.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// ref. http://compro.tsutajiro.com/archive/181015_incexc.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = (ll)2e18 + 5;
const ll MOD = 1000000007;  // 1e9 + 7

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

ll lcm(ll a, ll b) {
  if (a/gcd(a,b) > INF / b) { // a*b/gcd(a,b) > INF. too large
    return INF;
  } else {
    return a / gcd(a,b) * b;
  }
}

// Mevius Transform.
// - dp.size() == 1ll<<n.
// - dp must be initialzed by g
void MeviusTransform(vector<ll>& dp, ll n) {
  rep(i,n)rep(bit,1ll<<n) {
    if (bit>>i&1) {
      dp[bit] -= dp[bit^(1ll<<i)];
    }
  }
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout << setprecision(10) << fixed;

  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  vector<double> p(n);
  rep(i,n) {
    cin >> p[i];
    p[i] /= 100;
  }

  vector<ll> dp(1ll<<n);
  // initialzation
  rep(bit,1ll<<n) {
    if (bit == 0) { continue; } // Skip empty state bit.

    ll mul = 1; // lcm of all selected values.
    rep(i,n) {
      if (bit>>i&1) {
        mul = lcm(mul,a[i]);
      }
    }
    dp[bit] = m/mul; // count of intersection at bit state.
  }

  // Mevius Transform
  MeviusTransform(dp,n);

  // Calculate answer
  double ans = 0;
  rep(bit,1ll<<n) {
    double prob = 1.0; // probability of selected bit state.
    rep(i,n) {
      prob *= ((bit>>i&1) ? p[i] : 1-p[i]);
    }
    ans += prob * abs(dp[bit]);
  }
  cout << ans << endl;
}



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

using namespace std;

typedef long long ll;

#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

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

int main(){
	int n, m, k[31]={}, s[32]={}, tmp=0, cnt=0;
	cin >> n >> m;
	rep(i, n){
		cin >> k[i];
		rep(j, k[i]){
			cin >> tmp;
			++s[tmp - 1];
		}
	}

	rep(i, m){
		if(s[i] == n) ++cnt;
	}

	cout << cnt << endl;

	return 0;
}


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

const int N = 2005;

#define int long long

int gcd(int x, int y) {
	return (!y) ? x : gcd(y, x % y);
}

int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

int n, A[N][N], pr[N], cnt;
bitset <100005> isp;

void prework(int tot) {
	for(int i = 1; i < 100005; ++ i) isp[i] = 1;
	isp[1] = 0;
	for(int i = 1; cnt < tot; ++ i) {
		if(isp[i]) pr[++ cnt] = i;
		for(int j = 1; j <= cnt && pr[j] * i <= 100000; ++ j) {
			isp[i * pr[j]] = 0;
			if(i % pr[j] == 0) {
				break;
			}
		}
	}
}

main() {
	isp = 0;
	cin >> n;
	n += 2;
	prework(n * 2 + 2);
	//for(int i =1; i <= cnt; ++ i) cerr << pr[i] << " ";
	//puts("");
	for(int i = 0; i <= n + 1; ++ i) {
		for(int j = 0; j <= n + 1; ++ j) {
			A[i][j] = 1;
		}
	}
	int now = 0;
	for(int i = 1; i <= n; i += 2) {
		int nx = i, ny = 1;
		int G = pr[++ now];
		while(nx <= n && ny <= n) {
			A[nx][ny] *= G;
			++ nx, ++ ny;
		}
	}
	for(int i = 3; i <= n; i += 2) {
		int nx = 1, ny = i;
		int G = pr[++ now];
		while(nx <= n && ny <= n) {
			A[nx][ny] *= G;
			++ nx, ++ ny;
		}
	}
	
	for(int i = n; i >= 1; i -= 2) {
		int nx = n, ny = i;
		int G = pr[++ now];
		while(nx && ny <= n) {
			A[nx][ny] *= G;
			-- nx, ++ ny;
		}
	}
	
	for(int i = n - ((n & 1) ^ 1); i >= 1; i -= 2) {
		int nx = i, ny = 1;
		if(i == n) continue;
		int G = pr[++ now];
		while(nx && ny <= n) {
			A[nx][ny] *= G;
			-- nx, ++ ny;
		}
	}
	for(int i = 1; i <= n; ++ i) {
		for(int j = 1; j <= n; ++ j) {
			if((i + j) & 1) {
				//cerr << i <<" " << j << endl;
				//cerr << A[i][j - 1] <<" " << A[i - 1][j] <<" " << A[i + 1][j] <<" " << A[i][j + 1] << endl;
				A[i][j] = lcm(lcm(A[i][j - 1], A[i - 1][j]), lcm(A[i + 1][j], A[i][j + 1])) + 1;
			}
		}
	}
	for(int i = 2; i <= n - 1; ++ i) {
		for(int j = 2; j <= n - 1; ++ j) {
			printf("%lld", A[i][j]);
			if(j != n - 1) putchar(' ');
			//assert(max(A[i][j], A[i - 1][j]) % min(A[i][j], A[i - 1][j]) == 0);
			//assert(max(A[i][j], A[i][j - 1]) % min(A[i][j], A[i][j - 1]) == 0);
		}
		puts("");
	}
}

Measured memory_bytes: 10240
N,K = map(int,input().split())
A = list(map(int,input().split()))

ma = [0]*N
pr = [0]*N
flag = 0
i = 0
ne = A[i]
#print(1)
ma[i] = 1
pr[i] = 1
#print(ne)

while(flag == 0):
  #map判定
  if(ma[ne-1] == 0):
    ma[ne-1] = 1
    pr[ne-1] = i+2
  else:
    #print('flag!')
    flag = 1
    break
  
  #Kに到達(ループなし)
  if(i == K-1):
    #print('fin!')
    flag = 2
    break
  
  #更新
  ne = A[ne-1]
  i+=1
  #print(ne)

#print('---')
if(flag == 1):
  #calc
  start = pr[ne-1]
  #print('start = '+str(start))
  dist = i+2 - start
  #print('dist = '+str(dist))
  
  tmp = (K-start)%dist + start
  #print('tmp = '+str(tmp))
  
  #print(pr)
  ind = pr.index(tmp)
  #print('ind = '+str(ind))
  ne = A[ind]
  #for x in range(N):
  #  if(pr[x] == tmp):
  #    ne = A[x]

print(ne)
#print(pr)
#print(ma)


Measured memory_bytes: 92780
#problems1
N=int(input())
d=[]
for _ in range(N):
    x,y=map(int,input().split())
    d.append((x,y,x+y))
d.sort(key=lambda x:-x[2])
t=0
a=0
for i in range(N):
    if i%2==0:
        #高橋くん
        t+=d[i][0]
    else:
        a+=d[i][1]
print(t-a)    

Measured memory_bytes: 25336
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

# N, K = LI()
# A = LI()

# for i in range(N - K):
#     if A[i] < A[i + K]:
#         ans = "Yes"
#     else:
#         ans = "No"
#     print(ans)


N, K = LI()
A = LI()
for i in range(N - K):
    if A[i] < A[i + K]:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

Measured memory_bytes: 33692
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;ll
#define Nmax 400005
#define OFF 100001
using namespace std;

ll n;
string a,b;

bool OK(int lg){
    for (int i=a.size()-lg,j=0;i<a.size();i++,j++){
        if (a[i] != b[j])
            return 0;
    }
    return 1;
}

int main()
{
    cin >> n;
    cin >> a >> b;
    int lg = 0,ans = 0;;
    while (lg < a.size()){
        lg++;
        if (OK(lg)) ans = lg;
    }
    cout << 2 * n - ans << '\n';


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;

int func(string a){
  string s = "";
  if( 'a' <= a[0] && a[0] <= 'z' ) a = '1' + a;
  s += a[0];
  for(int i=1; i<a.size(); i++){
    if( 'a' <= a[i] && a[i] <= 'z' && 'a' <= a[i-1] && a[i-1] <= 'z' ) s += '1';
    s += a[i];
  }

  int ret = 0;
  for(int i=0; i<s.size(); i++){
    if( '0' <= s[i] && s[i] <= '9') continue;

    if( s[i] == 'm' ) ret += (s[i-1]-'0') * 1000;
    if( s[i] == 'c' ) ret += (s[i-1]-'0') * 100;
    if( s[i] == 'x' ) ret += (s[i-1]-'0') * 10;
    if( s[i] == 'i' ) ret += (s[i-1]-'0') * 1;
  }
  // cerr << s << " " << ret << endl;
  return ret;
}

string func1(int n){
  string s = "";
  string a = "mcxi";
  int q = 1000;
  for(int i=0; i<4; i++){
    if( n / q != 0 ){
      s += to_string(n / q) + a[i];
      n %= q;
    }
    q /= 10;
  }

  string ret = "";
  for(char c: s){
    if( c == '1' ) continue;
    ret += c;
  }

  return ret;
}

int main(void) {

  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    string a, b;
    cin >> a >> b;

    int sum = func(a) + func(b);
    // cerr << func(a) << " " << func(b) << " " << sum << endl;
    cout << func1(sum) << endl;

  }



  return 0;
}


// EOF

Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S; cin >> S;
	int N = S.size();
	bool ans = true;
	for(int i = 0; i < N; i++){
		for(int j = i + 1; j < N; j++){
			if(S[i] == S[j]) ans = false;
		}
	}
	if(ans) cout << "yes" << endl;
	else cout << "no" << endl;
}

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

int main(int argc, char *argv[]){
  int N,K;
  cin>>N>>K;
  vector<long long> X(N,0);
  vector<long long> S(X.size()-K+1,0);
  for(int i=0; i<N; i++){
    long long x;
    cin>>x;
    X[i]=x;
  }
  if(N==1){
    cout<<X[0]<<endl;
    return 0;
  }
  for(int left=0,right=K-1; left<=X.size()-K; left++,right++){
    int l=abs(X[left])+abs(X[right]-X[left]);
    int r=abs(X[right])+abs(X[right]-X[left]);
    S[left]=min(l,r);
  }
  sort(S.begin(),S.end());
  cout<<S[0]<<endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	int n, x, t; cin >> n >> x >> t;
	int ans; ans = ((n-1) / x + 1) * t;
	cout << ans << endl;
}


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

int main()
{
	double a,b,c,d,e,f,x,y;
	
	while(cin >> a >> b >> c >> d >> e >> f)
	{
		x=(c*e-b*f)/(a*e-b*d);
		y=(c*d-a*f)/(b*d-a*e);
		if(-0.0004<x&&x<=0)x=0;
		if(-0.0004<y&&y<=0)y=0;
		printf("%.3lf %.3lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 1236