akhauriyash/Code-Regression huggingface dataset:
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
typedef long long ll;
//#include <stack>
//#include <queue>
#define MOD 1000000007

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int tile[2010][2010]={};
int cnt[2010][2010][4]={};

int main(){
    int H,W;
    cin >> H >> W;
    string S;
    string tmpS;

    for( int hi = 1 ; hi <= H ; hi++ ){
        cin >> S;
        for( int wi = 1 ; wi <= W  ; wi++ ){
            tmpS = S.substr(wi-1,1);
            if(tmpS =="#") tile[hi][wi] = 0;
            else tile[hi][wi] = 1;
        }
    }
    int left = 0;
    int above = 1;
    int under = 2;
    int right = 3;
    int ih,iw,iv;
    for( int hi = 1 ; hi <= H ; hi++ ){
        for( int wi = 1 ; wi <= W  ; wi++ ){
            if(tile[hi][wi] != 0){
                ih = hi; iw = wi-1; iv = left;
                cnt[hi][wi][iv] = cnt[ih][iw][iv] * tile[ih][iw]  + 1;
                ih = hi-1; iw = wi; iv = above;
                cnt[hi][wi][iv] = cnt[ih][iw][iv] * tile[ih][iw]  + 1;
            }
        }
    }
    for( int hi = H ; hi >= 1 ; hi-- ){
        for( int wi = W ; wi >= 1  ; wi-- ){
            if(tile[hi][wi] != 0){
                ih = hi; iw = wi+1; iv = right;
                cnt[hi][wi][iv] = cnt[ih][iw][iv] * tile[ih][iw]  + 1;
                ih = hi+1; iw = wi; iv = under;
                cnt[hi][wi][iv] = cnt[ih][iw][iv] * tile[ih][iw]  + 1;
            }
        }
    }

    int ans = 0;
    int sum;
    for( int hi = H ; hi >= 1 ; hi-- ){
        for( int wi = W ; wi >= 1  ; wi-- ){
            sum = 0;
            for( int vi = 0 ; vi < 4 ; vi++ ){
                sum+= cnt[hi][wi][vi];
            }
            ans = max(sum-3,ans);
        }
    }
    cout << ans << endl;
    /*
    for( int vi = 0 ; vi < 4 ; vi++ ){
        for( int hi = 1 ; hi <= H ; hi++ ){
            for( int wi = 1 ; wi <= W  ; wi++ ){
                cout <<  cnt[hi][wi][vi];
                cout << " ";
            }
            cout << "" << endl;
        }
        cout << "" << endl;
    }
    */

}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==1)
	{
		cout<<"Hello World"<<endl;
	}
	else
	{
		int a,b;
		cin>>a>>b;
		cout<<a+b;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cerr<<' ';cerr<<elem;}cerr<<endl;}

struct UnionFind{
	vi par;		//par[i]:=(0以上の場合iの親. 0未満の場合はiを含むグループのサイズ).
	int num;	//num:=(グループの数).
	
	UnionFind(int n):par(n,-1),num(n){}//Constructor.
	
	void init(){fill(ALL(par),-1), num=par.size();}
	int root(int x){return (par[x]<0)?x:par[x]=root(par[x]);}//Recrusion.
	int size(int x){return -par[root(x)];}
	bool same(int x,int y){return root(x)==root(y);}
	bool unite(int x,int y){
		x=root(x), y=root(y);
		if(x==y) return false;//Do nothing.
		if(size(x)<size(y)) swap(x,y);//Merge technique(x<-y).
		par[x]+=par[y];
		par[y]=x;
		num--;
		return true;
	}
};

int main(){
	int n,m;
	cin>>n>>m;
	
	UnionFind uf(n);
	REP(i,m){
		int x,y,z;
		cin>>x>>y>>z;
		x--, y--;
		uf.unite(x,y);
	}
	
	cout<<uf.num<<endl;
}

Measured memory_bytes: 3796
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,x,t;
   cin>>n>>x>>t;
   if(n%x==0)
    n/=x;
   else
   {
       n/=x;
       n++;
   }
   cout<<n*t<<endl;
}


Measured memory_bytes: 3616
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

num = 10 ** 6 + 1 #適当に値を入れる
L = [0 for i in range(num)]
ans = 0
N = int(input())
A = getlist()
for i in range(N):
	L[A[i]] += 1

for i in range(num):
	if L[i] >= 1:
		if L[i] == 1:
			ans += 1
		c = 2
		while i * c <= num - 1:
			L[i * c] = 0; c += 1

print(ans)

Measured memory_bytes: 164168
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int N, Q;
	cin >> N >> Q;

	const int AM = 500001, RM = 708;
	pair<int, int> to[AM];
	int ne[AM], he[RM][RM] = {};
	int cnt[RM] = {};

	int C[AM];
	rep(i, N) {
		cin >> C[i];
	}

	int kotae[AM];
	rep1(i, Q) {
		int l, r;
		cin >> l >> r;
		l--;
		r--;

		int L = l / RM;
		int R = r / RM;

		if (L == R) {
			set<int> ST;
			int kari = 0;
			for (int j = l; j <= r; j++) {
				if (ST.find(C[j]) == ST.end()) {
					kari++;
					ST.insert(C[j]);
				}
			}
			kotae[i] = kari;
		}
		else {
			cnt[L]++;
			to[i] = mp(l, r);
			ne[i] = he[L][R];
			he[L][R] = i;
		}
	}
	int tmp[RM * 2];
	rep(i, RM) {
		if (cnt[i] == 0) continue;

		bool A[AM] = {};
		int kari = 0;
		for (int j = i + 1; j < RM; j++) {

			for (int t = he[i][j]; t; t = ne[t]) {
				int kt = 0;
				int kari2 = kari;
				int l = to[t].first;
				int r = to[t].second;
				for (int k = l; k < i * RM + RM; k++) {
					if (!A[C[k]]) {
						A[C[k]] = 1;
						kari2++;
						tmp[kt++] = C[k];
					}
				}
				for (int k = j * RM; k <= r; k++) {
					if (!A[C[k]]) {
						A[C[k]] = 1;
						kari2++;
						tmp[kt++] = C[k];
					}
				}
				kotae[t] = kari2;
				cnt[i]--;
				rep(k, kt) {
					A[tmp[k]] = 0;
				}
			}
			if (cnt[i] == 0) break;

			for (int k = j * RM; k < j * RM + RM; k++) {
				if (!A[C[k]]) {
					A[C[k]] = 1;
					kari++;
				}
			}
		}
	}

	rep1(i, Q) {
		co(kotae[i]);
	}

	Would you please return 0;
}

Measured memory_bytes: 16008
#include <iostream>
#include <vector>
using namespace std;
typedef long long lli;
lli n;
vector<lli> a;
lli dp[100005][2][2];
int main(int argc, char const *argv[]) {
    cin >> n;
    lli x;
    char c;
    cin >> x;
    a.push_back(x);
    for(lli i = 1;i < n;i++){
        cin >> c >> x;
        if(c == '-') a.push_back(x*-1);
        if(c == '+'){
            if(a.back() > 0) a.back() += x;
            else a.push_back(x);
        }
    }
    for(lli i = 0;i < a.size();i++){
        dp[i][0][0] = dp[i][1][0] = dp[i][1][1] = -100000000000000;
    }
    if(a.size() == 1){
        cout << a[0] << endl;
        return 0;
    }
    dp[2][0][0] = dp[2][1][1] = a[0]+a[1];
    for(lli i = 2;i < a.size();i++){
        if(a[i] < 0){
            dp[i+1][0][0] = dp[i][0][0]+a[i];
            dp[i+1][1][0] = max(dp[i][1][0]+a[i],dp[i][1][1]-a[i]);
            dp[i+1][1][1] = max(dp[i][1][0]+a[i],max(dp[i][1][1]-a[i],dp[i][0][0]+a[i]));
        }else{
            dp[i+1][0][0] = dp[i][0][0]+a[i];
            dp[i+1][1][0] = max(dp[i][1][0]+a[i],dp[i][1][1]-a[i]);
            dp[i+1][1][1] = max(dp[i][1][0]+a[i],dp[i][1][1]-a[i]);
        }
    }
    cout << max(max(dp[a.size()][0][0],dp[a.size()][1][0]),dp[a.size()][1][1]) << endl;
    return 0;
}


Measured memory_bytes: 4340
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

bool comp(pair<string,pair<ll,ll> > a,pair<string,pair<ll,ll> > b){
    if(a.first != b.first){
        return a.first < b.first;
    }
    else{
        return a.second.first > b.second.first;
    }
}
int main(void){
    ll n;
    cin>>n;
    vector<pair<string,pair<ll,ll> > > ngo(n);
    rep(i,n){
        cin>>ngo[i].first>>ngo[i].second.first;
        ngo[i].second.second = i+1;
        
    }
    sort(ngo.begin(),ngo.end(),comp);
    rep(i,n){
        cout<<ngo[i].second.second<<endl;
    }
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, a, b) = readLine()!!.split(' ').map(String::toLong)

    if ((b - a) % 2 == 0L) {
        println((b - a) / 2)
        return
    }
    val left = a+(b-a-1)/2
    val right = (n-b+1)+(n-a-(n-b+1))/2
    println(Math.min(left,right))
}

Measured memory_bytes: 38136
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
string str[350];
int s[350][350];
int n,m;
int k,cnt;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m>>k;
//	cout<<n<<' '<<m<<' '<<k<<'\n';
	for(int i=1;i<=n;i++){
		cin>>str[i];
		str[i]='!'+str[i];
		bool flag=1;
		for(int j=1;j<=m;j++){
			if(str[i][j]=='#'){
				flag=0;
				break;
			}
		}
		if(flag){
			if(s[i-1][1]){
				for(int j=1;j<=m;j++)s[i][j]=s[i-1][j];
			}
		}
		else{
			for(int j=1;j<=m;j++){
				if(str[i][j]=='#'){
					cnt++;
					s[i][j]=cnt;
					continue;
				}
				if(s[i][j-1]){
					s[i][j]=s[i][j-1];
				}
				else s[i][j]=cnt+1;
			} 	
		}	
	}
	int i=n;
	while(s[i][1]&&i>0)i--;
	while(s[i][1]==0&&i>0){
		for(int j=1;j<=m;j++)s[i][j]=s[i+1][j];
		i--;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<s[i][j]<<' ';
		}
		cout<<'\n';
	}
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>

using namespace std;

int x[10];

bool check( int i, int l, int r )
{
  bool retl = false, retr = false;
  
  if ( i == 10 )
    return true;

  if ( x[i] > l )
    retl = check( i+1, x[i], r );
  
  if ( x[i] > r )
    retr =  check( i+1, l, x[i] );

  return ( retl || retr );
}

int main()
{
  int n;
  cin >> n;
  
  for ( int i = 0; i < n; ++i )
    {
      for ( int j = 0; j < 10; ++j )
        {
          cin >> x[j];
        }
      if ( check( 1, x[0], -1 ) )
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  
  return 0;
}

Measured memory_bytes: 1152
/*Author : Yuvraj Singh
 * Patience is Power
 * 
 * */
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const long long mod = 1e9 + 7;
#define ar array

ll power(ll x,ll y) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return ((temp%mod)*(temp%mod))%mod; 
    else
        return (((x%mod)*(temp%mod))%mod*(temp%mod))%mod; 
}

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

bool cmp(pair<int,int>a,pair<int,int>b){
	return a.second<b.second;
}

void solve(){
	ll n; cin>>n;
	ll dp[2001]={0};
	dp[3]=1,dp[4]=1,dp[5]=1,dp[6]=2,dp[7]=3,dp[8]=4;
	for(int i=9;i<=n;i++){
		dp[i] = (dp[i-1]%mod + dp[i-3]%mod)%mod;
	}
	cout<<dp[n]<<"\n";
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	//int t; cin>>t;
	//while(t--)
		solve();
		
    return 0;
}



Measured memory_bytes: 3624
n, y = map(int, input().split())
y = y//1000
for i in range(n+1):
    for j in range(n+1):
        k = n - (i+j)
        if k>=0 and i+j+k==n and i*10+j*5+k==y:
            print(i,j,k)
            exit()
print(-1, -1, -1)

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

int main() {
  string s;
  
  cin >> s;
  if(s=="Sunny"){
    s="Cloudy";
  }else if(s=="Cloudy"){
    s="Rainy";
  }else if(s=="Rainy"){
    s="Sunny";
  }

  cout << s <<endl;
  return 0;
}


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

int main()
{
	int value = 0;
	std::string s;

	std::cin >> s;

	for ( int i = 0; i < 4; i++ )
	{
		if ( s[i] == '+' )
		{
			++value;
		}
		else if ( s[i] == '-' )
		{
			--value;
		}
	}

	std::cout << value << std::endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX_H = 15;
const int MAX_W = 1e3 + 5;

int grid [MAX_H][MAX_W];
int cnt [MAX_H];
int id [MAX_H];

int main () {
  int n, m, K;
  cin >> n >> m >> K;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      char c;
      cin >> c;

      if (c == '1') grid[i][j] = 1;
    }
  }

  int ans = n * m + 100;
  for (int mask = 1; mask < 1 << n; mask += 2) {
    int cur_id = 0;
    for (int i = 0; i < n; i++) {
      if (mask & 1 << i) {
	cur_id++;
      }
      id[i] = cur_id;
    }

    int cuts = cur_id - 1, fail = 0;
    for (int j = 0; j < m; j++) {
      for (int i = 0; i < n; i++) {
	cnt[id[i]] += grid[i][j];
      }

      int flag = 0;
      for (int i = 1; i <= cur_id; i++) {
	if (cnt[i] > K) {
	  flag = 1;
	}
      }

      if (flag) {
	cuts++;

	for (int i = 1; i <= cur_id; i++) {
	  cnt[i] = 0;
	}
	
	for (int i = 0; i < n; i++) {
	  cnt[id[i]] += grid[i][j];
	}

	for (int i = 1; i <= cur_id; i++) {
	  if (cnt[i] > K) {
	    fail = 1;
	  }
	}
      }
    }

    for (int i = 1; i <= cur_id; i++) {
      cnt[i] = 0;
    }

    if (!fail) {
      ans = min(ans, cuts);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
#include<queue>
#define MM 1000000007
using namespace std;
int main(void)
{
	long long a,b,c,x;
	int n,i;
	scanf("%d",&n);
	a=1;	b=1;	c=1;
	for(i=0;i<n;i++)	{
		a=a*10;
		a=a%MM;
		b=b*9;
		b=b%MM;
		c=c*8;
		c=c%MM;
	}
	x=a+c-b-b;
	x=(x+MM+MM)%MM;
	printf("%lld\n",x);
	return 0;
}


Measured memory_bytes: 1736
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(Int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(Int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using Int = long long;
using ll = long long;
using P = pair<Int,Int>;
using vi = vector<Int>;
using vvi = vector<vi>;
using vp = vector<P>;
using vvp = vector<vp>;

const Int INF = (1LL<<50);

void solve(long long N, std::vector<long long> a){
  Int s = 0;
  rep(i, N) s ^= a[i];
  rep(i, N) cout << (a[i] ^ s) << (i == N-1 ? "\n" : " ");
}

int main(){
  std::cout << std::fixed << std::setprecision(15);
  long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 4848
import itertools


def is_compatible(hyp, testimonies):
    return all((key in hyp) == (val == 1) for key, val in testimonies.items())


def is_compatible_all(hyp, all_testimonies):
    return all(is_compatible(hyp, all_testimonies[i]) for i in hyp)


def main():
    n = int(input())
    all_testimonies = [{}]
    for _ in range(n):
        ai = int(input())
        statements = {}
        for _ in range(ai):
            x, y = input().split()
            statements[int(x)] = int(y)
        all_testimonies.append(statements)

    for e in all_cases(n):
        if is_compatible_all(e, all_testimonies):
            print(len(e))
            return


def all_cases(n):
    for r in range(n, -1, -1):
        for ensemble in itertools.combinations(range(1, n + 1), r):
            yield set(ensemble)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {

  int a,b,c,d ;
  cin >> a >> b >> c >> d ;

  if(a+b>c+d)
  {
   cout << "Left" << endl ;    
  }else if(a+b==c+d)
  {
   cout << "Balanced" << endl ;        
  }else
    cout << "Right" << endl ;        
    
 return 0 ;
}  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


int main() {

	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a.at(i);
	}
	int max_dist = abs(k - a.at(n - 1)) + abs(0 - a.at(0));

	rep(i, n - 1) {
		int num = 0;
		num = abs(a.at(i) - a.at(i + 1));
		max_dist = max(max_dist, num);
	}

	cout << k - max_dist << endl;


	return 0;

}



Measured memory_bytes: 3972
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define MAX_N (100000)
#define MAX_M (100000)

using namespace std;

void dfs(vector<vector<int>> &adj_lists, int *group_nodes, int cur, int group) {
  group_nodes[cur] = group;
  for (int nxt : adj_lists[cur]) {
    if (group_nodes[nxt] <= 0) {
      dfs(adj_lists, group_nodes, nxt, group);
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, ps[MAX_N], xs[MAX_M], ys[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d", &ps[i]);
    ps[i]--;  // NOTE modified input
  }
  for (int j = 0; j < M; j++) {
    scanf("%d %d", &xs[j], &ys[j]);
    xs[j]--;  // NOTE : modified input
    ys[j]--;  // NOTE : modified input
  }

  // create graph
  vector<vector<int>> adj_lists(N, vector<int>());
  // add edges
  for (int j = 0; j < M; j++) {
    const int x = xs[j], y = ys[j];
    adj_lists[x].push_back(y);
    adj_lists[y].push_back(x);
  }

  // solve
  int ans = 0, num_groups = 0;
  int group_nodes[MAX_N] = {};
  for (int i = 0; i < N; i++) {
    if (group_nodes[i] <= 0) {
      num_groups++;
      dfs(adj_lists, group_nodes, i, num_groups);
    }
  }
  for (int i = 0; i < N; i++) {
    if (group_nodes[i] == group_nodes[ps[i]]) {
      ans++;
    }
  }
  printf("%d\n", ans);

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> cnts(N + 1, 0);
  for (int i = 2; i < N + 1; i++) {
    int n = i;
    for (int j = 2; j * j < n + 1; j++) {
      while (n % j == 0) {
        cnts[j]++;
        n /= j;
      }
    }
    if (n > 1) cnts[n]++;
  }
  auto f = [cnts](int x) {
    int res = 0;
    for (auto cnt : cnts) {
      if (x - 1 <= cnt) res++;
    }
    return res;
  };
  // (1, 75), (5, 15), (3, 5, 5), (3, 25)
  int res = 0;
  res += f(75);
  res += f(15) * (f(5) - 1);
  res += f(5) * (f(5) - 1) * (f(3) - 2) / 2;
  res += f(25) * (f(3) - 1);
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+50;
typedef long long ll;
vector<pair<int,int> > tree[maxn];
int n;
bool vis[maxn];
ll dis[maxn];
void dfs(int x)
{
    vis[x]=1;
    for(int i=0; i<tree[x].size(); i++)
    {
        int v=tree[x][i].first;
        int w=tree[x][i].second;
        if(!vis[v])
        {

            dis[v]=dis[x]+w;
            dfs(v);
        }
    }
}
int main()
{
    int u,v,w;
    int q,k;
    scanf("%d",&n);
    int cnt=0;
    for(int i=0; i<n-1; i++)
    {
        scanf("%d%d%d",&u,&v,&w);
        tree[u].push_back(make_pair(v,w));
        tree[v].push_back(make_pair(u,w));
    }
    int from,to;
    memset(vis,0,sizeof(vis));
    //memset(dis,0,sizeof(vis));
    scanf("%d%d",&q,&k);
    //memset(vis,0,sizeof(vis));
    dfs(k);
    ll ans=0;
    while(q--)
    {
        scanf("%d%d",&from,&to);
        ans=dis[from]+dis[to];
        //cout << dis[from] << " " << dis[to] << endl;
        printf("%lld\n",ans);
    }

    //cout << "Hello world!" << endl;
    return 0;
}


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

int main()
{
  int a, b;
  auto v = std::vector<std::array<int, 2> *>{};

  while (std::cin >> a >> b)
  {
    auto o = new std::array<int, 2>{a, b};
    v.push_back(o);
  }

  for (auto j = 0; j < v.size(); j++)
  {
    auto inner = *v[j];
    if ((inner)[0] == 0 && (inner)[1] == 0)
      break;

    std::sort(inner.begin(), inner.end());
    std::cout << inner[0] << " " << inner[1] << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main () {
  long long a, b, c;
  cin >> a >> b >> c;
  if (c - a - b > 0 && 4*a*b < (c - a - b) * (c - a - b)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	map<int, int> m;
	int64_t sum = 0;
	for (int i = 0; i < N; i++) {
		int64_t cur;
		cin >> cur;
		m[cur] += 1;
		sum += cur;
	}

	int Q;
	cin >> Q;
	for (int j = 0; j < Q; j++) {
		int b, c;
		cin >> b >> c;

        int num = m[b];
        m[c] += num;
        m[b] = 0;

        sum += ((c - b) * num);
        cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 8008
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            int N = int.Parse(line[0]);
            int M = int.Parse(line[1]);
            int L = 0;
            int R = N;

            for(int i=0; i<M; i++)
            {
                S = Console.ReadLine();
                line = S.Split(' ');
                if(int.Parse(line[0]) > L)
                {
                    L = int.Parse(line[0]);
                }
                if(int.Parse(line[1]) < R)
                {
                    R = int.Parse(line[1]);
                }
            }

            if(R - L < 0)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine(R - L + 1);
            }


        }
    }
}

Measured memory_bytes: 15292
N=int(input())
P=[list(map(int,input().split(' '))) for i in range(N)]
T=[P[i][0] for i in range(N)]
A=[P[i][1] for i in range(N)]
t=T[0]
a=A[0]
k=1
for i in range(1,N):
	k1 = int((T[i-1]*k-1)//T[i]+1)
	k2 = int((A[i-1]*k-1)//A[i]+1)
	k = max(k1,k2)
print(k*(T[-1]+A[-1]))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what

using namespace std;
 
const int N = (int) 4e3 + 10;
const int M = (int) 700;
const ll LINF = (ll) 1e18;
const int mod = (int) 1e9 + 7;
const double EPS = (double) 1e-9;
const double PI =  3.14159265359;

int n, m, q;
char a[N/2][N/2];
int cnt[N][N], pref[N][N];

const int nx[4] = {1, -1, 0, 0};
const int ny[4] = {0, 0, 1, -1};

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    cin >> n >> m >> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] + (a[i][j] == '1');
            if (a[i][j] == '0') 
                continue;
            for (int k = 0; k < 4; k++) {
                int gi = i + nx[k], gj = j + ny[k];
                if (a[gi][gj] == '1') {
                    pref[gi + i][gj + j]++;
                }
            }
        }
    }
    for (int i = 1; i <= n + n; i++) {
        for (int j = 1; j <= m + m; j++) {
            pref[i][j] += pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1];
        }
    }
    while (q--) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        int ans = 0;
        ans += cnt[x2][y2]-cnt[x1-1][y2]-cnt[x2][y1-1]+cnt[x1-1][y1-1];
        ans *= 2;
        x1 *= 2;
        x2 *= 2;
        y1 *= 2;
        y2 *= 2;
        ans-=pref[x2][y2]-pref[x1-1][y2]-pref[x2][y1-1]+pref[x1-1][y1-1];
        cout << ans/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 100736
#include <stdio.h>

int main()
{
    int H, W, i, j;
    
    while(1){
        
        scanf("%d %d", &H, &W);
        
        if(H==0 && W==0){
            break;
        }
        
        for(j=1; j<=H; j++){
            for(i=1; i<=W; i++){
                if((i+j)%2==0){
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 572
def solve(x, y, dir, s, w, h)
  @vis[y][x] = 1
  (x>0 && dir!=1 && s[y][x-1]=="." && @vis[y][x-1]==0) ? (lf = 1+solve(x-1,y,2,s,w,h)):(lf = 0)
  (x<w-1 && dir!=2 && s[y][x+1]=="." && @vis[y][x+1]==0) ? (ri = 1+solve(x+1,y,1,s,w,h)):(ri = 0)
  (y>0 && dir!=3 && s[y-1][x]=="." && @vis[y-1][x]==0) ? (up = 1+solve(x,y-1,4,s,w,h)):(up = 0)
  (y<h-1 && dir!=4 && s[y+1][x]=="." && @vis[y+1][x]==0) ? (dw = 1+solve(x,y+1,3,s,w,h)):(dw = 0)
  return lf+ri+up+dw
end
  

while (ln = gets.chomp) != "0 0"
  w,h = ln.split.map(&:to_i)
  s = h.times.map{gets.chomp.split("")}
  
  @vis = Array.new(h).map{Array.new(w,0)}
  for i in 0..(h-1)
    for j in 0..(w-1)
      if s[i][j] == "@"
        sx = j
        sy = i
        break
      end
    end
  end
  
  puts solve(sx, sy, 0, s, w, h)+1
end


Measured memory_bytes: 7048
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		
		if(line.equals("A")) {
			System.out.println("T");
		}else if(line.equals("T")){
			System.out.println("A");
		}else if(line.equals("C")){
			System.out.println("G");
		}else if(line.equals("G")){
			System.out.println("C");
		}
		
	}

}


Measured memory_bytes: 21204
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var N string = readLine()
	var flag bool = strings.Contains(N, "7")

	if flag {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1756
#include <iostream>
#include <string>
#include <set>

int main(){
 int N;
 std::cin>>N;

 std::string tmp;
 std::set<std::string> s;
 for(int i=0;i<N;i++){
  std::cin>>tmp;
  s.insert(tmp);
 }

 int ans=0;
 for(auto p:s){
  ans++;
 }

 std::cout<<ans<<std::endl;

 return 0;
}

Measured memory_bytes: 19232
s = int(input())

# 今までに出てきた数字を格納
set_num = set()

set_num.add(s)
ans = 1

while True:
    ans += 1
    if s%2 == 1:
        s = s*3+1
    else:
        s = s//2
    if s in set_num:
        break
    else:
        set_num.add(s)

print(ans)

Measured memory_bytes: 3060
#include<cstdio>
const int max_n = 100;
int main(){
	int n;
	int u,k,v;
	int G[100][100];
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			G[i][j] = 0;
		}
	}
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&u,&k);
		for(int j=1;j<=k;j++){
			scanf("%d",&v);
			G[u-1][v-1] = 1;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			printf("%d",G[i][j]);
			if(j!=n-1) printf(" ");
			else if(j == n-1) printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2724
x,y=map(int,input().split())
if x in [1,3,5,7,8,10,12]:
    x=1
elif x in [4,6,9,11]:
    x=2
else:
    x=3
if y in [1,3,5,7,8,10,12]:
    y=1
elif y in [4,6,9,11]:
    y=2
else:
    y=3

if x==y:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int N;
main()
{
	cin>>N;
	if(__builtin_popcount(N)==1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	if(N%2==1)
	{
		for(int i=2;i<=N;i+=2)
		{
			cout<<"1 "<<i<<endl;
			cout<<i<<" "<<i+1<<endl;
			cout<<"1 "<<N+i+1<<endl;
			cout<<N+i+1<<" "<<N+i<<endl;
			if(i==2)
			{
				cout<<i+1<<" "<<N+1<<endl;
			}
		}
	}
	else
	{
		for(int i=2;i<=N-3;i+=2)
		{
			cout<<"1 "<<i<<endl;
			cout<<i<<" "<<i+1<<endl;
			cout<<"1 "<<N+i+1<<endl;
			cout<<N+i+1<<" "<<N+i<<endl;
			if(i==2)
			{
				cout<<i+1<<" "<<N+1<<endl;
			}
		}
		int a=N-2,b=N-1,c=N;
		cout<<(a^c)<<" "<<a<<endl;
		cout<<a<<" "<<c<<endl;
		cout<<(a^c)<<" "<<N+c<<endl;
		cout<<N+c<<" "<<N+a<<endl;
		cout<<a<<" "<<b<<endl;
		cout<<(a^c^1)<<" "<<N+b<<endl;
	}
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define endl '\n'
#define int ll
#define gcd __gcd
#define popcount(x) __builtin_popcountll(x)
#define fill(x, y) memset(x, y, sizeof(x))
#define search(arr, c) binary_search(arr.begin(), arr.end(), c)
// default binary search returns a bool
 
// int dx[]={1,0,-1,0}; 
// int dy[]={0,1,0,-1}; //4 Direction 
 
// int dx[]={1,1,0,-1,-1,-1,0,1}; 
// int dy[]={0,1,1,1,0,-1,-1,-1};  // 8D
 
void solve(){

    string a;
    cin >> a;
    if (a[0] == 'R' && a[1] == 'R' && a[2] == 'R') {
        cout << 3 << endl;
        return;
    }
    else if (a[0] =='R' && a[1] =='R'){
        cout << 2 << endl;
        return;
    }
    else if(a[1] =='R' && a[2] == 'R'){
        cout << 2 << endl;
        return;
    }
    else  {
        for (int i = 0 ; i < 3 ; i++){
            if (a[i] == 'R'){
                cout << 1 << endl;
                return;
            }
        }
        
    }

    cout << 0 << endl;
    return;
}
 
 
int32_t main(){
 
    #ifndef ONLINE_JUDGE 
  
    freopen("input.txt", "r", stdin); 
  
    // freopen("output.txt", "w", stdout); 
  
    #endif 
 
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    int t = 1;
    // cin >> t;
    for (int tt = 0 ; tt < t ; tt++){
        // cout << "Case " << (tt+1) <<": " << endl;
        solve();
    }
    
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll p = 998244353;

template<typename T> struct Mod {
  vector<T> fact, factInv;
  Mod() {}
  Mod(T n, T p = 1e9 + 7) : fact(n + 1), factInv(n + 1) {
    fact[0] = 1;
    for (T i = 1; i < n + 1; ++i) fact[i] = fact[i - 1] * i % p;
    for (T i = 0; i < n + 1; ++i) factInv[i] = modPow(fact[i], p - 2, p);
  }
  T modPow(T x, T n, T m) {
    if (n == 0) return 1;
    T res = modPow(x * x % m, n / 2, m);
    if (n & 1) res = res * x % m;
    return res;
  }
  T modComb(T n, T k, T p = 1e9 + 7) {
    return ((fact[n] * factInv[k]) % p * factInv[n - k]) % p;
  }
};

int main() {
  ll N, A, B, K; cin >> N >> A >> B >> K;
  Mod<ll> md(N, p);
  ll ans = 0;
  for (int i = 0; i <= N; ++i) {
    if ((K - i * A) % B) continue;

    int j = (K - i * A) / B;
    if (j < 0 || N < j) continue;
    ans += md.modComb(N, i, p) * md.modComb(N, j, p) % p;
    ans %= p;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std; 

//しゃくとり方でとく//
int main(void){
 int N,K;
 string S;
 vector<int> A;

 cin>>N>>K;
 cin>>S;

 int cnt=0;
 int now=0;

 for(int i=0; i<S.length();i++){
  if(S[i]==('1'-now)){
   cnt++;
  }
  else{
   now=1-now;
   A.push_back(cnt);
   cnt=1;
  }
 }
 A.push_back(cnt);          
 
 if(A.size()%2==0)A.push_back(0);
 
 int sum,left,right,ans,nowleft,nowright;
 sum=0;
 left=0;
 right=0;
 nowleft=0;
 nowright=0;
 ans=0;

 while(nowright<A.size()){
  right=min(left+2*K+1,(int)A.size());

  while(nowleft<left){
   sum-=A[nowleft];
   nowleft++;
  }
  while(nowright<right){
   sum+=A[nowright];
   nowright++;
  }
  left+=2;
  ans=max(sum,ans);
 }

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

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a = vector<int>(n + 1);
    vector<int> b = vector<int>(n + 1);
    vector<int> c = vector<int>(n);
    for (int i = 1; i < n + 1; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < n + 1; i++) {
        cin >> b[i];
    }
    for (int i = 1; i < n; i++) {
        cin >> c[i];
    }
    int s = 0;
    int previous = -1;
    for (int i = 1; i < n + 1; i++) {
        if (previous == a[i] -1) {
            s += c[previous];
        }
        s += b[a[i]];
        previous = a[i];
    }
    cout << s << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{

int a,b,c;

scanf("%d",&a);

scanf("%d",&b);
	
scanf("%d",&c);
	
if(a<b&&b<c)

{

printf("Yes\n");
	
}

else

{

printf("No\n");

}

return 0;

}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define h1 7897897897897897
#define h2 7897466719774591
#define b1 98762051
#define b2 98765431
#define inf 1000000000
#define pi 3.1415926535897932384626
#define LMAX 9223372036854775807
#define ll long long
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pii>
#define SET(a, b) memset(a, b, sizeof(a));
#define all(x) (x).begin(), (x).end()
#define flush fflush(stdout)
#define debug printf("Hello\n")
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
int n, m, k, x, y, sum, cnt;
double ans;
double prob[3005], dp[3005][3005];
int main () {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  FOR(i, 1, n) cin >> prob[i];
  dp[0][0] = 1;
  FOR(i, 1, n) {
    FOR(j, 0, i) {
      dp[i][j] += dp[i-1][j] * (1-prob[i]);
      if (j != 0) dp[i][j] += dp[i-1][j-1] * prob[i];
    }
  }
  FOR(i, n/2+1, n) ans += dp[n][i];
  cout << fixed << setprecision(10) << ans;
  return 0;
}

Measured memory_bytes: 69120
N = int(input())
cntS = {}
for _ in range(N):
  s = ''.join(sorted(input()))
  if s in cntS:
    cntS[s] += 1
  else:
    cntS[s] = 1

print(sum([cntS[key]*(cntS[key]-1)//2 for  key in cntS]))

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

int main(int argc, const char * argv[]) {
    int N, M;
    cin >> N >> M;
    
    map<int, int> m;
    for (int i = 0; i < N; i++) {
        int K;
        cin >> K;
        for (int j = 0; j < K; j++) {
            int A;
            cin >> A;
            m[A]++;
        }
    }
    
    int count = 0;
    for (auto v : m) {
        if (v.second == N) {
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}

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

dp = [0] * (n + 10)
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[n - 1])


Measured memory_bytes: 13980
# 標準入力
num = int(input())
data = input().split()

# 操作回数の初期化
count = 0

while(True):
    exist_odd = False
    for i in range(num):
        if int(data[i]) % 2 != 0:
            exist_odd = True
        
    if exist_odd:
        break

    for i in range(num):
        data[i] =  int(data[i]) // 2
        
    count += 1

print(count)

Measured memory_bytes: 3060
import sys
from fractions import gcd
from itertools import permutations, combinations, accumulate
from collections import deque
from heapq import heappush, heappop, heapify
import math

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

MOD = 10**9 + 7

def main():
    h,a = list(map(int,input().split()))
    ans = math.ceil(h/a)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 5052
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			int[] d = new int[n+m];
			for(int i = 0;i < n+m;i++){
				d[i] = scan.nextInt();
			}
			Arrays.sort(d);
			int max = d[0];
			for(int i = 0;i < n+m-1;i++){
				if(max < d[i+1]-d[i]){
					max = d[i+1] - d[i];
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 63024
def main():
    d = int(input())
    c = [int(i) for i in input().split()]
    s = [[int(i) for i in input().split()] for _ in range(d)]
    t = [int(input()) - 1 for _ in range(d)]
    score = 0
    last = [0] * 26
    for i in range(d):
        score += s[i][t[i]]
        last[t[i]] = i + 1
        for j in range(26):
            score -= c[j] * (i + 1 - last[j])
        print(score)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9500
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;



int main(){

    ll N, K;
    cin >> N >> K;

    string s;
    cin >> s;

    vector <ll> v;
    ll tmp = 1;
    bool last = false;
    for(int i = 1; i < N; i++){
        if(s[i] != s[i-1]){
            v.push_back(tmp);
            tmp = 1;
            if(i == N - 1) last = true;
        }
        else{
            tmp ++;
        }
    }
    v.push_back(tmp);

    tmp = v.size();
    for(int i = 0; i < K; i++){
        tmp -= 2;
        if(tmp <= 1){
            tmp = 1;
            break;
        }
    }

    cout << N - tmp << endl;

    /*
    for(int i = 0; i < v.size(); i++){
        ll tmp = v[i];
        if(i != 0) tmp += v[i];

    }
    */

}

Measured memory_bytes: 1528
// Date: 2020-05-31

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int a[N];
int main() {
    FIO;
    int n;
    cin >> n;
    LL sum = 0;
    rep(i, 0, n) cin >> a[i], sum += a[i];
    if(n == 0) {
        if(a[0] == 1) cout << 1;
        else cout << -1;
        return 0;
    }
    if(a[0]) {
        cout << -1;
        return 0;
    }
    LL ans = 1, nl = 1;
    int flag = 1;
    rep(i, 1, n) {
        LL m = min(2*nl, sum);
        if(m < a[i]) {
            flag = 0;
            break;
        }
        ans += m;
        nl = m-a[i];
        sum -= a[i];
    }
    if(!flag) ans = -1;
    cout << ans;

    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == 'R')
            cnt++;
    }
    if (cnt == 2)
    {
        if (s[1] == 'R')
            cout << 2 << endl;
        else
            cout << 1 << endl;
    }
    else
        cout << cnt << endl;
}

Measured memory_bytes: 3580
a = gets.to_i
n = gets.split.map(&:to_i)
a.times{|t|
  if n[t] != t + 1 then
    n[n.index(t+1)] = n[t]
    n[t] = t + 1
    break
  end
    }
  a.times{|t|
  if n[t] != t + 1 then
    print "NO"
    break
  end
  if t == a-1 then
    print "YES"
  end
    }

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(ll (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(ll (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll h, w, d;
	cin >> h >> w >> d;

	vector<P> b(h*w+1);
	Vec csum(h*w+1);
	rep(i, h){
		rep(j, w){
			ll a;
			cin >> a;
			b[a] = mp(i, j);
		}
	}

	repn(i, h*w){
		if(i >= d) csum[i] = abs(b[i].fs-b[i-d].fs)+abs(b[i].sc-b[i-d].sc)+csum[i-d];
	}

	ll q;
	cin >> q;
	rep(i, q){
		ll l, r, ans = 0;
		cin >> l >> r;
		co(csum[r]-csum[l]);
	}

	return 0;
}


Measured memory_bytes: 3200
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String S = in.next();
            int ans = 0;
            for (int i = 0; i < 4; i++) {
                if ('+' == S.charAt(i)) ans++;
                else ans--;
            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 21460
#C
import math

a, b, h, m = list(map(int, input().split()))

th = abs((h/12 + m/60/12) * 2 * math.pi - m/60 * 2 * math.pi)
if th <= 180:
    c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(th))
else:
    th = th - 180
    c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(th))
    
print(c)

Measured memory_bytes: 9448
n=int(input())
a=list(map(int,input().split()))
ans=[0]*n
res=[]
for i in range(1,n+1):
    t=sum(ans[n-i:n:n-i+1])%2
    if (t-a[n-i])%2==1:
      ans[n-i]=1
      res.append(n-i+1)
print(sum(ans))
print(*res)

Measured memory_bytes: 14008