akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  using P = pair<int, int>;
  vector<P> vp;
  for(int i=0;i<n;i++){
    int v,w;
    cin>>v>>w;
    vp.emplace_back(v,w);
  }
  auto cmp=[](P a,P b){return (long long)a.first*b.second>(long long)b.first*a.second;};
  sort(vp.begin(),vp.end(),cmp);
  double ans=0;
  for(auto p:vp){
    int w=min(p.second,m);
    ans+=double(p.first)*double(w)/double(p.second);
    m-=w;
  }  
  cout<<ans<<endl;
  return 0;
}



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


int main() {
   int n;
   cin >> n;
   vector<int> p;
   cout << n << ':' ;
   int count=0;
       for (int i=2; i<=n; i+=2) {
           if (i>sqrt(n)) {cout << ' ' << n ;break;}
           bool a=false;
           for (int j=0; j<p.size(); j++) {
               if (p[j]>sqrt(i)) break;
               if (i%p[j]==0) {
                   a=true;break;
               }
           }
           if (a) continue;
           p.push_back(i);
           while (n%i==0) {
               n/=i;
               cout << ' ' << i;
           }
           if (i==2) i--;
       }
       cout << endl;
}


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

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int distance = Integer.parseInt(scan.next());
    int time = Integer.parseInt(scan.next());
    int speed = Integer.parseInt(scan.next());

    String result;
    if (distance > time * speed) {
      result = "No";
    } else {
      result = "Yes";
    }

    PrintWriter out = new PrintWriter(System.out);
    out.println(result);
    out.flush();
  }
}


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

int digits(unsigned long p){
    if(p == 0) return 1;
    return (int)(log10l(p) + 1);
}

int main(){
    int a, b;
    while(cin >> a >> b){
        cout << digits(a+b) << endl;
    }
    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

#define si(x) scanf("%d", &x)

int main(){
    bool ok = false;
    string s, t;

    cin >> s >> t;

    if (s.length() == t.length() - 1 ){
        if(s == t.substr(0, s.length())){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }else
    {
        cout << "No\n";
    }
    

    return 0;
}

Measured memory_bytes: 3628
using System;
using System.IO;

  class Program {
    static void Main(string[] args) {

      string lenA = Console.ReadLine();
      for (int i = 0; i < 3; i++)
      {
        if (lenA[i] == '7')
        {
          
            Console.WriteLine("Yes");
            return;
        }
      }

      Console.WriteLine("No");
      return;
    }
  }

  


Measured memory_bytes: 25572
/*
	f(v, d, d1):- d = d + w(P[v], v), d1

*/
#include <bits/stdc++.h>

using namespace std;
const int maxv = 100001;
vector< pair<int, int> > A[maxv], T[maxv];
int P[maxv], solve;
int a, b, c, N, root;


inline void tree_build( int v, int parent ){

	vector< pair<int, int> >::iterator x = A[v].begin();

	for( ; x != A[v].end(); ++x ){
	    if( x->first == parent )
	    	continue;
		T[v].push_back( *x ),
		tree_build( x->first, v );
	}
}

inline void sol( int v, int &len ){

    vector< pair<int, int> >::iterator x = T[v].begin();

    int tplen = 0;
    int ch1 = 0;
    int ch2 = 0;
    for( ; x != T[v].end(); ++x ){
		tplen = x->second;
		sol( x->first, tplen );
		if( ch1 <= tplen ){
			ch2 = ch1;
			ch1 = tplen;
		}else
		if( ch2 < tplen )
			ch2 = tplen;
	}

	solve = max( solve, ch1 + ch2 );
	len += ch1;
}

int main( void ){

	//freopen("input.in", "r", stdin);
	scanf( "%d", &N );

	for( int i = 1; i < N; ++i )
		scanf( "%d%d%d", &a, &b, &c ), 
		++a, 
		++b,
		P[b] = a,
		A[a].push_back( make_pair( b, c ) ),
		A[b].push_back( make_pair( a, c ) );


	for( int i = 1; i <=N && !root; ++i )
		root = ( !P[i] )?i:root;	

	tree_build( root, 0 );
	int len = 0;
	sol( root, len );

	printf("%d\n", solve);

	return 0;
}

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if ((x-r) >= 0 && (x+r) <= W && (y+r) <= H && (y-r) >= 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

int main() {
  
  int  A, B, C, K;
  cin >> A >> B >> C >> K;
  int count = 0;
  while (A > 0 && K > 0) {
    A -= 1;
    K -= 1;
    count++;
  }
  while (B > 0 && K > 0) {
    B -= 1;
    K -= 1;
  }
  while (C > 0 && K > 0) {
    C -= 1;
    K -= 1;
    count--;
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define whole(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define ins insert
#define _(a) #a << " : " << (a)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> x;
#define v first
#define id second
//----------------------------------------------------------
const int inf = 1e9, maxn = 1e6 + 1;
const ll inff = 1e18;
const ld eps = 1e-9;
int n, k, m;
int cnt[maxn];
string s;
void input ()
{
	cin >> s;
	n = s.length ();
	s.ins (0, " ");
	for (int i = 1; i <= n; ++i)
		cnt[i] = cnt[i - 1] ^ (1 << (s[i] - 'a'));
}
map <int, int> l;
int f[maxn];
void solve ()
{
	l.ins (mp (0, 0));
	f[0] = 0;
	for (int i = 1; i <= n; ++i)
	{
		f[i] = n;
		auto it = l.find (cnt[i]);
		if (it != l.end ()) f[i] = min (f[i], f[it -> id] + 1);
		for (int j = 0; j < 26; ++j)
		{
			int x = (1 << j) ^ cnt[i];
			// cerr << x;
			auto it2 = l.find (x);
			if (it2 != l.end ())
				f[i] = min (f[i], f[it2 -> id] + 1);
		}
		it = l.find (cnt[i]);
		if (it == l.end ()) l.ins (mp (cnt[i], i));
		else if (f[it -> id] > f[i]) it -> id = i;
		// cerr << i << ' ';
	}
	cout << f[n];
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie (NULL);
	cout.tie (NULL);
	input ();
	solve ();
}


Measured memory_bytes: 14740
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define debugV(x,n) for(int i = 0;i < n;i++) cerr << x[i] << " "; cerr<<endl;
#define rep(i,a,b) for(int i = (int)a;i < (int)b;i++)
#define F first
#define S second
#define pb push_back
typedef pair<int,int> ii;
typedef long long int ll;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-5;

int main(){
	int v[3];
	cin >>v[0]>>v[1];
	sort(v,v+2);
	if(v[0]!=1)
		puts("1");
	else if(v[1]!=2)
		puts("2");
	else puts("3");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
string a, b, c;
int main(){
  cin >> a >> b >> c;
  int a_size = a.size();
  int b_size = b.size();
  if(a[a_size - 1] == b[0] && b[b_size - 1] == c[0]){
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

int main(){
	int a,b;
  	cin >> a >> b;
  	if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0)
      	cout << "Possible" << endl;
  	else
    	cout << "Impossible" << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int n;
cin>>n;
for(int i=0;i<=100;i++)
  {
  for(int j=0;j<=100;j++)
    {
      if(4*i+7*j==n)
      {
      cout<<"Yes";
      system("pause");
      return 0;
      }
      
    }
  }
cout<<"No"; 
system("pause");
return 0;
}


Measured memory_bytes: 504
#include<iostream>
#include<cstring>
#include<iomanip>
using namespace std;
double dp[3000+1][3000+1];
double arr[3001];
double greaterhead(int n,int i)
{  if(i==0)
    return 1;
    if(n==0)
   return 0;
   if(dp[n][i]>-0.9)
    return dp[n][i];
   	double ans=arr[n]*greaterhead(n-1,i-1);
   double p=(1-arr[n])*greaterhead(n-1,i);
  //  cout<<ans<<" "<<p<<" ";
    dp[n][i]=(ans+p);
    return dp[n][i];
}
/*
greaterhead(int n,int *arr,int i,int j)
{  dp[1][1]=arr[1]*(1-arr[2])+(1-arr[1])*arr[2];
for(int i=1;i<=n;i++)
   for(int j=1;j<=n;j++)
{   if(i==1&&j==1)
   continue;
    if(i==1)
     dp[i][j]=(1-arr[j])*dp[i][j-1];
     else if(j==1)
      dp[i][j]=(arr[i])*dp[i-1][j];
      else
       dp[i][j]=arr[j-1]*dp[i]

}
	
}*/
int main()
{ memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	  cin>>arr[i];
	 printf("%0.10lf\n",greaterhead(n,(n+1)/2));

	  
}

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

const int H = 10010;
const int N = 1010;

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

    int h, n;
    cin >> h >> n;
    vector<int> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i] >> B[i];
    }

    int dp[H];
    for(int i = 0; i <= H; i++){
        dp[i] = 1e9;
    }
    dp[0] = 0;

    for(int i = 1; i <= H; i++){
        for(int j = 0; j < n; j++){
            if(i - A[j] < 0){
                continue;
            }
            if(dp[i - A[j]] + B[j] < dp[i]){
                dp[i] = dp[i - A[j]] + B[j];
            }
        }
    }

    int ans = 1e9;
    for(int i = H; i >= h; i--){
        if(dp[i] == 1e9) continue;
        ans = min(ans, dp[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}

ll mod(ll x, ll y){if(x>=0) return x%y;if(x%y==0) return 0;return y+x%y;}

int main(){
    ll N, L, T;
    cin>>N>>L>>T;
    ll X[N], W[N];
    ll a;
    rep(i, N){
        cin>>X[i]>>W[i];
        if(i==0){
            a=X[i];
            X[i]=0;
        }
        else{
            X[i]-=a;
        }
    }
    ll cnt=0;
    if(W[0]==1){
        rep(i,N){
            if(W[i]==2){
                if(X[i]-2*T>0){
                    X[i]=(X[i]-2*T)%L;
                }
                else{
                    cnt+=(2*T-X[i])/L+1;
                    X[i]=L+(X[i]-2*T)%L;
                }
            }
        }
        sort(X, X+N);
        cnt%=N;
        rep(i, N){
            cout<<(X[(N-cnt+i)%N]+T+a)%L<<endl;
        }
    }
    else{
        rep(i, N){
            if(W[i]==1){
                cnt+=(X[i]+2*T)/L;
                X[i]=(X[i]+2*T)%L;
            }
        }
        sort(X, X+N);
        cnt%=N;
        rep(i, N){
            cout<<mod(X[(cnt+i)%N]-T+a, L)<<endl;
        }
    }
}

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

#define int              long long 
#define FOR( i, m, n )   for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )      FOR( i, 0, n )
#define ALL( a )         (a).begin(), (a).end()

template<class T>bool chmax( T& a, const T& b ) { if( a < b ) { a = b; return 1; } return 0; }
template<class T>bool chmin( T& a, const T& b ) { if( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;

signed main(){
  int n, m;
  while( cin >> n >> m, n ){
  int sum1 = 0, sum2 = 0;
  vector<int> a( n ), b( m );
  REP( i, n ) {
    cin >> a[i];
    sum1 += a[i];
  }
  REP( i, m ){
    cin >> b[i];
    sum2 += b[i];
  }

  int ans1 = INF, ans2 = INF;
  REP( i, n ){
    REP( j, m ){
      int cha = a[i];
      int chb = b[j];
      if( sum1 - cha + chb == sum2 - chb + cha ){
	if( ans1 + ans2 > a[i] + b[j] ){
	  ans1 = a[i];
	  ans2 = b[j];
	}
      }
    }
  }

  if( ans1 != INF ) cout << ans1 << " " << ans2 << endl;
  else              cout << -1 << endl;

  }
}



Measured memory_bytes: 3096
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int X;
  cin>>X;
  int ans = 1;
  int tmp;
  for(int i=2;i*i<=X;++i) {
    tmp = i;
    while(tmp*i<=X) tmp *= i;
    ans = max(ans, tmp);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3496
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll INF=1e9+7;

ll d[20][20];
ll dp[1<<20][20];

int main()
{
    ll v,e;
    cin >> v >> e;
    rep(i,20){
        rep(j,20){
            d[i][j]=INF;
        }
    }
    rep(i,e){
        ll s,t,p;
        cin >> s >> t >> p;
        d[s][t]=p;
    }
    for(ll s=0;s<(1<<v);s++){
        rep(i,v){
            dp[s][i]=INF;
        }
    }
    dp[(1<<v)-1][0]=0;
    for(ll s=(1<<v)-2;s>=0;s--){
        rep(i,v){
            rep(j,v){
                if(!(s>>j&1)){
                    //cout << dp[s][i] << endl;
                    dp[s][i]=min(dp[s][i],dp[s|(1<<j)][j]+d[i][j]);
                    
                }
            }
        }
    }
    
    
    cout << (dp[0][0]>=INF?-1:dp[0][0]) << endl;
    return 0;
} 


Measured memory_bytes: 8236
N,Y=[int(a) for a in input().split()]
for x in range(N+1):
    for y in range(N+1-x):
        z=N-x-y
        if 10*x+5*y+z==Y//1000:
            print(x,y,z)
            import sys
            sys.exit()
print(-1,-1,-1)

Measured memory_bytes: 40556
if __name__=='__main__':
    index_src = input()
    index = index_src.split(' ')
    alls = int(index[0])
    adds = int(index[1])
    numbers_src = input().split(' ')
    numbers_int =[]
    for i in numbers_src:
        numbers_int.append(int(i))
    numbers_int.sort()
    numbers_int.reverse()
    ans = 0
    for i in range(0,adds):
        ans += numbers_int[i]
    print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

using ll =long long;
const ll L = 1e18;

ll a[100005];

int main()
{
    ll N;
    cin >> N;
    ll p = 1;
    bool zf = false;
    for(int i = 0;i < N;i++)
    {
        cin >> a[i];
        p *= a[i];
        if(a[i] == 0)
        {
            zf = true;
        }
    }
    if(zf == true)
    {
        cout << 0 << endl;
        return 0;
    }
    ll p2 = p;
    for(int i = 0;i < N;i++)
    {
        p2 /= a[i];
    }
    if(p2 == 1 && p <= L)
    {
        cout << p << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


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

class LCA{
public:
  const int LOG_V=30;                 //log V (自分で決めて)
  int V;                              //言わずもがな頂点数
  vector<vector<int> > G;             //グラフの隣接リストの表現
  int root;                         //根のノード番号
  vector<vector<int> > parent;        //親を2^k回辿って到達する頂点(根を通りすぎる場合は-1とする)
  vector<int> depth;                  //根からの深さ
  int ok;
  
  LCA():V(-1){}
  LCA(int V,int root = 0):V(V),G(V),root(root),parent(LOG_V,vector<int>(V)),depth(V),ok(0){}
  
  void add_edge(int a, int b){
    assert(a < V && b < V);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  void dfs(int v,int p,int d){
    assert(v < V);
    parent[0][v] = p;
    depth[v] = d;
    for(int to:G[v]) if(to != p) dfs(to,v,d+1);
  }
  
  //vからn個上の祖先
  int getAnc(int v,int n){
    for(int k=0; k<LOG_V ;k++) if((v != -1) && (n>>k&1)) v=parent[k][v];
    return v;
  }

  //初期化
  void build(){
    ok = 1;
    //parent[0]とdepthを初期化する。
    dfs(root,-1,0);
    //parentを初期化する
    for(int k=0; k+1<LOG_V ;k++)
      for(int v=0; v<V ;v++)
        if(parent[k][v] < 0)parent[k+1][v] = -1;
        else parent[k+1][v] = parent[k][parent[k][v]];
  }

  //uとvのLCAを求める
  int lca(int u,int v){
    assert(ok);
    assert(u < V && v < V);
    //uとvの深さが同じになるまで親を辿る
    if(depth[u]>depth[v]) swap(u,v);
    v = getAnc(v,depth[v] - depth[u]);
    
    if(u==v) return u;
    //二分探索でLCAを求める
    for(int k=LOG_V-1; k>=0 ;k--)
      if(parent[k][u] != parent[k][v]){
        u=parent[k][u];
        v=parent[k][v];
      }
    return parent[0][u];
  }
};

int main(){
  int n;
  cin>>n;
  LCA lca(n);
  
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      lca.add_edge(i,c);
    }
  }

  lca.build();

  int q;
  cin>>q;
  while(q--){
    int u,v;
    cin>>u>>v;
    cout<<lca.lca(u,v)<<endl;
  }
  return 0;
}



Measured memory_bytes: 23276
using System;

namespace _2_A {
    class Program {
        static void Main (string[] args) {
            var input = Console.ReadLine ().Split ();
            var a = Convert.ToInt32 (input[0]);
            var b = Convert.ToInt32 (input[1]);

            if (a < b) {
                Console.WriteLine ("a < b");
            } else if (a > b) {
                Console.WriteLine ("a > b");
            } else {
                Console.WriteLine ("a == b");
            }
        }
    }
}



Measured memory_bytes: 16036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;
	int n = s.size();
	int m, l, r, k = (n+1) / 2;
	if (!(n & 1))k++;

	if (n % 2 == 0) {
		if (s[n / 2] != s[n / 2 - 1]) {
			cout << k - 1 << endl;
			return 0;
		}
		else {
			l = n / 2 - 1;
			r = n / 2;
		}
		m = s[n / 2] - '0';
	}
	else {
		m = s[(n - 1) / 2] - '0';
		l = r = (n - 1) / 2;
	}

	while (0 < l) {
		l--;r++;
		if (s[l] - '0' != m || s[r] - '0' != m)break;
		k++;
	}

	cout << k << endl;

}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int n,m; cin>>n>>m;
    UnionFind tree(n);
    rep(i,m){
        int x,y,z; cin>>x>>y>>z;
        tree.unite(x-1,y-1);
    }
    map<int,int> tmp;
    int ans=0;
    rep(i,n){
        if(tmp[tree.root(i)]==0){
            tmp[tree.root(i)]++; ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;

int main() {
	ll mod = 998244353LL;
	int n; cin >> n;
	vector<ll> a(n);
	int s = 0;
	for (int i = 0; i < n; i++) cin >> a[i], s += a[i];
	vector<vector<ll>> dp(n + 2, vector<ll>(100000));
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j + a[i] < 100000; j++) {
			dp[i + 1][j] = (dp[i + 1][j] + 2 * dp[i][j] % mod) % mod;
			dp[i + 1][j + a[i]] = (dp[i + 1][j + a[i]] + dp[i][j]) % mod;
		}
	}
	ll ans = 1;
	for (int i = 0; i < n; i++) ans *= 3, ans %= mod;
	ll k = 0;
	for (int i = (s - 1) / 2 + 1; i < 100000; i++) {
		k += dp[n][i];
		k %= mod;
	}
	ans -= 3 * k %mod;
	ans = (ans + mod) % mod;
	if (s & 1) {
		cout << ans << endl;
		return 0;
	}

	vector<vector<ll>> dp2(n + 2, vector<ll>(100000));
	dp2[0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j + a[i] < 100000; j++) {
			dp2[i + 1][j] = (dp2[i + 1][j] + dp2[i][j]) % mod;
			dp2[i + 1][j + a[i]] = (dp2[i + 1][j + a[i]] + dp2[i][j]) % mod;
		}
	}
	ans = (ans + mod + 3 * dp2[n][s / 2] % mod) % mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 473712
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s,t;
    cin >> s >> t;
    
    int ans = 0;
    
    for ( int i = 0; i < 3; i++ )
        if ( s[i] == t[i] ) ans++;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<int> N;
  invec<int> A(N);

  for (auto i : A) {
    if (i % 2 == 0 && (i % 3 != 0 && i % 5 != 0))
      return "DENIED";
  }

  return "APPROVED";
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 384
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if 500 * i + 100 * j + 50 * k == X:
                ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
 
using namespace std;
typedef long long ll;


int main()
{
    double T, X;
    cin >> T >> X;
    cout << T/X << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int A, B;
  cin >> A >> B;
  cout << A * B / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
  while(1){
    int n,m;
    int a[1000];
    int ans=0;
    scanf("%d%d",&n,&m);
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
    }
    int x;

    for(int i=0;i<n-1;i++){
      for(int t=i+1;t<n;t++){
        x = a[i]+a[t];
        if(x>ans && x<=m){
          ans=x;
        }
      }
    }
    if(ans==0){
      printf("NONE\n");
    }
    else{
      printf("%d\n",ans);
    }
  }

  return 0;
}



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

using namespace std;

int a[105];
int main(){
   int n, m, x;
   for(int i = 0; i < 105; i++) a[i] = 0;
   cin >> n >> m >> x;
   for(int i = 0; i < m; i++){
        int x;
        cin >> x;
        a[x] = 1;
   }
   int ans = 105, cnt = 0;
   for(int i = x-1; i > 0; i--) if(a[i]) cnt++;
   ans = min(ans, cnt);
   cnt = 0;
   for(int i = x + 1; i < n; i++) if(a[i]) cnt++;
   cout << min(ans, cnt) << endl;
}


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

int main(){
    int n,A[1000],sum;
    double ave,sum1;
    while(1){
        cin >> n;
        if(n==0) break;
        sum = 0;
        for(int i=0;i<n;i++){
            cin >> A[i];
            sum += A[i];
        } 
        ave = 1.0*sum/n;
        sum1 = 0.0;
        for(int i=0;i<n;i++){
            sum1 += pow((ave-A[i]),2);
        }
        printf("%.5f\n",sqrt(sum1/n));
    }
    return 0;
}


Measured memory_bytes: 3152
from collections import deque
n = int(input())

d = deque(['a'])

while d:
    w = d.popleft()
    if len(w) == n:
        print(w)
    else:
        w_m = len(set(w))
        for i in range(w_m + 1):
            d.append(w + chr(ord('a') + i))


Measured memory_bytes: 11876
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
 ll n;
 cin >> n;
 ll sum=0;
 for(ll i=1;i<=n;i++){
    ll m=n/i;
     sum+=i*(1+m)*m/2;
 }
 cout << sum << endl;
}

Measured memory_bytes: 3600
N,M,K = map(int,input().split())
flag = 0
if (N*M)%2==0 and K==(N*M)//2:
    flag = 1
else:
    y = 0
    while y<=N:
        if N-2*y!=0 and (K-M*y)%(N-2*y)==0 and M>=(K-M*y)//(N-2*y)>=0:
            flag = 1
            break
        y += 1
if flag==1:
    print("Yes")
else:
    print("No")

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

int main(){
  string x;
  cin >> x;
  
  int l = x.size();
  int ans = 0, erase = 0;
  for(int i = 0; i < l; i++){
    char now = x.at(i);
    if(now == 'S') erase--;
    else{
      if(erase >= 0) ans += 2;
      if(erase < 0) erase++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 640
def mainFunc():
    N = int(input())
    ai = [0 for i in range(N)]
    m1, m2 = 0, 0
    for i in range(N):
        ai[i] = int(input())
        if m1 <= ai[i]:
            m2 = m1
            m1 = ai[i]
        elif m2 <= ai[i]:
            m2 = ai[i]

    ans = ""
    for i in range(N):
        ans += str(m1) if ai[i] < m1 else str(m2)
        ans += "\n"
    
    print(ans)
mainFunc()

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

typedef tuple<int, int, int, int> T;
vector<T> vec;
typedef pair<int, int> P;
vector<string> s;

void dfs( int sx, int sy, int ex, int ey )
{
	int cnt = 0;
	vector<P> p;
	for( int y = sy; y < ey; y++ ) {
		for( int x = sx; x < ex; x++ ) {
			if( s[y][x] == '#' ) {
				cnt++;
				p.push_back( P( x, y ) );
			}
		}
	}
	if( cnt == 1 ) {
		vec.push_back( T( sx, sy, ex, ey ) );
		return;
	}
	int x0, y0, x1, y1;
	tie( x0, y0 ) = p[0];
	tie( x1, y1 ) = p[1];
	if( x0 == x1 ) {
		int ymax = max( y0, y1 );
		dfs( sx, sy, ex, ymax );
		dfs( sx, ymax, ex, ey );
	}
	else {
		int xmax = max( x0, x1 );
		dfs( sx, sy, xmax, ey );
		dfs( xmax, sy, ex, ey );
	}
}

int main()
{
	int H, W, K;
	cin >> H >> W >> K;
	s = vector<string>( H );
	for( int i = 0; i < H; i++ ) {
		cin >> s[i];
	}

	dfs( 0, 0, W, H );
	vector<vector<int>> a( H, vector<int>( W ) );
	for( int k = 0; k < vec.size(); k++ ) {
		int sx, sy, ex, ey;
		tie( sx, sy, ex, ey ) = vec[k];
		for( int y = sy; y < ey; y++ ) {
			for( int x = sx; x < ex; x++ ) {
				a[y][x] = k + 1;
			}
		}
	}

	for( int i = 0; i < H; i++ ) {
		for( int j = 0; j < W; j++ ) {
			if( j ) cout << " ";
			cout << a[i][j];
		}
		cout << endl;
	}
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    cout << s.substr(0, 3) << '\n';

    return 0;
}


Measured memory_bytes: 3640
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

def kruskal(es, V):
    es.sort(key=lambda x:x[2])
    uf = UnionFind(V)
    res = 0
    for e in es:
        if not uf.same(e[0], e[1]):
            uf.union(e[0], e[1])
            res += e[2]
    return res

def resolve():
    N = I()
    xy = [LI() for _ in range(N)]

    # 辺の候補は、xyそれぞれでソートした隣同士の点の間のみに絞れる
    xy_x_asc = sorted(enumerate(xy), key=lambda x: x[1][0])
    xy_y_asc = sorted(enumerate(xy), key=lambda x: x[1][1])
    edge = []
    for i in range(N-1):
        xc = xy_x_asc[i][1][0]
        yc = xy_x_asc[i][1][1]
        xyc_num = xy_x_asc[i][0]
        xn = xy_x_asc[i+1][1][0]
        yn = xy_x_asc[i+1][1][1]
        xyn_num = xy_x_asc[i+1][0]
        edge.append([xyc_num, xyn_num, abs(xn-xc)])
    for i in range(N-1):
        xc = xy_y_asc[i][1][0]
        yc = xy_y_asc[i][1][1]
        xyc_num = xy_y_asc[i][0]
        xn = xy_y_asc[i+1][1][0]
        yn = xy_y_asc[i+1][1][1]
        xyn_num = xy_y_asc[i+1][0]
        edge.append([xyc_num, xyn_num, abs(yn-yc)])

    # print(edge)
    mst_cost = kruskal(edge, N)
    print(mst_cost)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 72456
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// greatest common divisor
long long gcd(long long a, long long b) {
  if (a==0 || b==0) return a+b;
  long long r = 1;
  while (r != 0) {
    r = a%b; a = b; b = r;
  }
  return a;
}

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


class DSemiCommonMultiple {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll n, m; cin >> n >> m;
      vector<ll> a(n);
      set<int> st;
      rep(i, n) {
        cin >> a[i];
        st.insert(a[i]);
      }

      ll gd = a[0];
      rep(i, n) {
        gd = lcm(gd, a[i]);
        if (gd >= INT_MAX) {
          gd = INT_MAX;
        }
      }

      vector<int> cnt(n);
      rep(i, n) {
        ll e = a[i];
        while(e%2==0) {
          cnt[i]++;
          e /= 2;
        }
      }

      rep(i, n) {
        if (cnt[0] != cnt[i]) {
          cout << 0 << endl;
          return;
        }
      }

      m -= gd/2;
      if (m >= 0) {
        cout << m/gd + 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
};

signed main() {
  DSemiCommonMultiple solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

using namespace std;

int main (void) {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for ( int i = 0; i < h; i++ ) {
        cin >> s.at(i);
    }

    long long ans = 0;
    for ( int i = 0; i < (1<<(h)); i++ ) {
        for ( int j = 0; j < (1<<(w)); j++ ) {
            int n_black = 0;
            for ( int row = 0; row < h; row++ ) {
                if ( ((i>>row) & 1) == 0 ) {
                    continue;
                }
                for ( int col = 0; col < w; col++ ) {
                    if ( ((j>>col) & 1) == 0 ) {
                        continue;
                    }
                    if ( s.at(row).at(col) == '#' )
                        n_black++;
                }
            }
            if ( n_black == k ) {
                ans++;
            }
        }
    }

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


Measured memory_bytes: 3568
import java.util.Scanner;

public class Main{
       public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
            while (true) {
                int h = sc.nextInt();
                int w = sc.nextInt();
                if (h == 0 && w == 0)
                    break;
                for (int i = 0; i < h; i++) {
                    for (int j = 0; j < w; j++) {
                        if(i % 2 == 0){
                            if(j % 2 == 0)
                            System.out.print("#");
                            else
                            System.out.print(".");
                        }else{
                            if(j % 2 == 0)
                            System.out.print(".");
                            else
                            System.out.print("#");
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
}


Measured memory_bytes: 34784
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int[] a = new int[6];
			for(int i=0;i<6;i++) a[i] = sc.nextInt();
			if(a[0]==-1 && a[1]==-1 && a[2]==-1 && a[3]==-1 && a[4]==-1 && a[5]==-1) break;
			
			int[] sum = new int[2];
			
			for(int c=0;c<2;c++){
				for(int i=1;i<a[3*c];i++){
					if(i%400==0 || (i%4==0 && i%100!=0)) sum[c]+=366;
					else sum[c]+=365;
				}
				for(int i=1;i<a[1+3*c];i++){
					if(i==2){
						if(a[3*c]%400==0 || (a[3*c]%4==0 && a[3*c]%100!=0)) sum[c]+=29;
						else sum[c]+=28;
					}else if(i==4 || i==6 || i==9 || i==11){
						sum[c]+=30;
					}else{
						sum[c]+=31;
					}
				}
				sum[c]+=a[2+3*c];
			}
			System.out.println(sum[1]-sum[0]);
		}
	}	
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll mp[555][555];
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
vector<ll> v;

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

void prime(){
	vector<bool> pri(100000);
	vector<ll> tmp;
	int cou = 0;
	for(int i = 2;;i++){
		if(!pri[i]){
			tmp.PB(i);
			for(int j = i;j < 100000;j+=i)pri[j] = true;
			cou++;
		}
		if(cou == 1010)break;
	}
	for(int i = 0,j = tmp.size() - 1;i < j;i++,j--){
		v.PB(tmp[i]);
		v.PB(tmp[j]);
	}
}

void seica(){
	REP(i,555)REP(j,555)mp[i][j] = 1;
	REP(i,500){
		REP(j,500){
			if((i+j) % 2 == 0){
				mp[i][j] *= v[(i+j)/2];
			}
			if((i+499-j) % 2 == 1){
				mp[i][j] *= v[501+(i+499-j)/2];
			}
		}
	}

	REP(i,500){
		REP(j,500){
			if((i + j) % 2){
				ll now = 1;
				REP(k,4){
					if(i+dy[k] >= 0 && i+dy[k] < 500 && j+dx[k] >= 0 && j+dx[k] < 500){
						ll hoge = gcd(now, mp[i+dy[k]][j+dx[k]]);
						now *= mp[i+dy[k]][j+dx[k]] / hoge;
					}
				}
				mp[i][j] = now + 1;
			}
		}
	}
}

int main(){

	int n;cin >> n;

	prime();
	//cout << v.size() << endl;
	seica();

	REP(i,n){
		REP(j,n){
			cout << mp[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 5504
from itertools import combinations_with_replacement


n,m,q = map(int,input().split())
num_lst = []
for i in range(q):
    num_lst.append(list(map(int,input().split())))
l = list(range(1,m+1))
A = list(combinations_with_replacement(l,n))

mx = 0
for now_A in A:
    score = 0
    for nums in num_lst:
        a,b,c,d = nums
        if now_A[b-1] - now_A[a-1] == c:
            score += d
    mx = max(mx,score)
print(mx)





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

n,q = map(int, input().split())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    G[a].append(b)
    G[b].append(a)


a = [0]*n
for i in range(q):
    p,x = map(int, input().split())
    p -= 1
    a[p] += x

# bfs
from collections import deque
q = deque()
q.append((0,0))
visited = [0]*n
ans = [0]*n
while q:
    cur, cost = q.popleft()
    if visited[cur]:
        continue
    visited[cur] = 1
    cost += a[cur]
    ans[cur] = cost
    for to in G[cur]:
        if not visited[to]:
            q.append((to, cost))

print(*ans)


Measured memory_bytes: 100428
H, W = map(int, input().split())
a = [["#"] * (W + 2) for i in range(H + 2)]

for i in range(H + 2):
    if i == 0 or i == H + 1:
        print("".join(a[i]))
    else:
        a[i][1:W + 1] = input().split()
        print("".join(a[i]))


Measured memory_bytes: 3060
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x = ni()

print(["No", "Yes"][x >= 30])

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

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    int c[6][6];
    for (int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++)
        {
            
            c[i][j] = s[j] == '#' ? 1 : 0;
        }
    }
    int count = 0;
    int bit = 0;
    while (bit < (1 << (h + w)))
    {
        bool mask[6][6];
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                mask[i][j] = false;
            }
        }
        for (int i = 0; i < h; i++)
        {
            if ((bit & (1 << i)) != 0)
            {
                for (int j = 0; j < w; j++)
                    mask[i][j] = true;
            }
        }
        for (int j = 0; j < w; j++)
        {
            if ((bit & (1 << (j + h))) != 0)
            {
                for (int i = 0; i < h; i++)
                    mask[i][j] = true;
            }
        }
        int sum = 0;
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                sum += !mask[i][j] ? c[i][j] : 0;
            }
        }
        if (sum == k)
            count += 1;
        bit += 1;
    }


    cout << count << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
		pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++) {
		div = (div * i) % MOD;
	}
	return (p * modinv(div)) % MOD;
}

int calc(int n, int a, int b, vector<int> v) {
	int result = 0;
	rep(i, n) {
		if (i % 2 == 0) {
			if (v[i] != a) result += 1;
		} else if (i % 2 == 1) {
			if (v[i] != b) result += 1;
		}
	}

	return result;
}

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

	vector< pair<ll, ll> > a = prime_factorize(P);

	ll max = 0, ans = 1;
	rep(i, a.size()) {
		pair<ll, ll> p = a[i];
		rep(j, p.second / N) ans *= p.first;
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> ii;
	

bool isPrime(int n){
	if(n<=1) return false;
	if(n==2) return true;
	int f = sqrt(n);
	rep(i, 2, f+1) if(n%i==0) return false;
	return true;
}

int main(){
	
	int a, b, c; cin >> a >> b;
	
	if(a>b) swap(a, b);
	if(a==1 && b==2) c = 3;
	if(a==1 && b==3) c = 2;
	if(a==2 && b==3) c = 1;
	
	cout << c << '\n';
	
	

	
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())

dic = {}

for i in range(N):
    S = input()
    dic[S] = dic.setdefault(S, 0) + 1

sdic = sorted(dic.items(), key=lambda x:x[1]*-1)

l = []

k = -1
for s in sdic:
    if k == -1:
        k = dic[s[0]]
    if k == dic[s[0]]:
        l.append(s[0])
    else:
        break

for s in sorted(l):
    print(s)

Measured memory_bytes: 47324
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0] && b[b.size()-1] == c[0]){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 256