akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin>>l.at(i);
    }
    int a=0;
    for (int i = 0; i < n-2; i++)
    {
        for (int j = i+1; j < n-1; j++)
        {
            for (int k = j+1; k < n; k++)
            {
                
                int b=max({l.at(i),l.at(j),l.at(k)});
                if (2*b-(l.at(i)+l.at(j)+l.at(k))<0 and l.at(i)!=l.at(j) and l.at(j)!=l.at(k) and l.at(k)!=l.at(i))
                {
                    a++;
                }
                
            }
            
        }
        
    }
    cout<<a<<endl;
    
    
    

    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const ll INF = 1e15;
typedef pair<ll,int> LL_IP;

typedef struct edge{

    int to;
    int cost;

}EDGE;

void dijkstra(int n,vector<vector<EDGE> >& G,int x,vector<ll>& d){
    /*頂点の個数、辺の情報、始点となる頂点、最短距離の情報*/

    /*最終的にdは経由点からの最短距離が格納される、その過程では暫定的な最短距離が格納され、最短距離が見つかれば、その都度更新される*/

    //vector<ll> d(n,INF);/*最終的な最短距離を保持、初期化はINF*/
    d[x] = 0;
    priority_queue<LL_IP,vector<LL_IP>,greater<LL_IP> > que;/*vectorのpriority_queueで暫定的な最短距離が小さい順に取り出す*/
    que.push(LL_IP(0,x));/*経由点からダイクストラを適用するので経由点の暫定的な最短距離のコストは0*/

    while(!que.empty()){/*queが空になれば最短距離が全て探索できたことになる*/

        LL_IP p = que.top();/*最短距離の１番小さいものの取り出し*/
        que.pop();/*取り出したので調べたとみなし、queから出す*/
        int v = p.second;/*取り出した頂点の番号*/
        if(d[v] < p.first){
            /*取り出した頂点からの最短距離よりも短い経路があるので更新の必要はない*/
            continue;
        }

        for(int i = 0;i < G[v].size(); i++){
            /*取り出した頂点から辺でつながっている頂点への最短距離を調べて現在の値より短ければ更新する*/
            EDGE e = G[v][i];/*取り出した頂点からつながっている頂点を1つ取り出す*/
            if(d[e.to] > d[v] + e.cost){
                /*現在の最短距離よりも、現在の頂点を経由する経路のほうが最短距離が短い場合は最短距離を更新し、次の頂点を調べる*/
                d[e.to] = d[v] + e.cost;/*最短経路の更新*/
                que.push(pii(d[e.to],e.to));/*先の頂点を調べるためqueに格納*/
            }              
        }
    }
}


int main(){

    int n,m,s,t,u,v,a,b;
    cin >> n >> m >> s >> t;
    vector<vector<EDGE> > GA(ARRAY_MAX),GB(ARRAY_MAX);/*n個の各頂点からそれ以外の頂点へのコスト*/
    vector<ll> A(ARRAY_MAX,INF),B(ARRAY_MAX,INF);/*最短経路*/

    REP(i,m){
        cin >> u >> v >> a >> b;
        u--;
        v--;/*配列の添え字へ合わせる*/
        /*無効グラフなので双方向にコストを保持*/
        GA[u].push_back(EDGE{v,a});
        GB[u].push_back(EDGE{v,b});
        GA[v].push_back(EDGE{u,a});
        GB[v].push_back(EDGE{u,b});
    }

    dijkstra(n,GA,s-1,A);//円
    dijkstra(n,GB,t-1,B);//スヌーク

    ll maxi = 1e15;
    vector<ll> cnt(ARRAY_MAX,1e15);

    for(int i = 0;i < n;i++){//最小コストの計算
        cnt[i] = A[i] + B[i];
    }

    for(int i = n-1;i >= 0;i--){//n-1年後は両替は頂点nでしかできない、以後同様にして累積minを求める
        cnt[i] = min(cnt[i],cnt[i+1]);
    }
    for(int i = 0;i < n;i++){
        cout << maxi-cnt[i] << endl;
    }



    return 0;
}

Measured memory_bytes: 17144
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#define N 200005
using namespace std;

struct st{
	int s, e, x;
} tq, a[N];

int n, q, mx;
bool v;
priority_queue<st> pq;

bool operator < (st p, st q) {
	return p.x > q.x;
}

bool cmp(st p, st q) {
	if (p.s != q.s) return p.s < q.s;
	return p.e < q.e;
}

int main()
{
	int i, t1, t2, t3;
	cin >> n >> q;
	for (i = 0; i < n; i++) {
		scanf("%d %d %d", &t1, &t2, &t3);
		a[i].s = t1 - t3;
		a[i].e = t2 - t3;
		a[i].x = t3;
	}
	sort(a, a + n, cmp);
	i = 0;
	while (q--) {
		scanf("%d", &t1);
		for (; i < n && a[i].s <= t1; i++) pq.push(a[i]);
		v = 0;
		while (!pq.empty()) {
			tq = pq.top();
			if (tq.e > t1) {printf("%d\n", tq.x); v = 1; break;}
			else pq.pop();
		}
		if (!v) puts("-1");
	}
    return 0;
}

Measured memory_bytes: 6772
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d",&a);
    scanf("%d",&b);
    if(a<b){
        printf("a < b");
    }else if(a>b){
        printf("a > b");
    }else{
        printf("a == b");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2104
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>

using namespace std;

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

int main()
{
	string s;
	cin>>s;
	
	bool ok = false;
	if(s.size()>=4)
	{
		if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')ok=true;
	}
	if(ok)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    set<int> st;
    for (int i = 0; i < n; i++)
    {
        long a;
        cin >> a;
        st.insert(a);
    }
    if (st.size()==n)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
}

Measured memory_bytes: 9600
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {


    string s;
    int n;

    cin >> s;
    
    while(s!="0"){
        int sum = 0;
        for(int i=0; i<s.size(); i++){
            n = s[i] - '0';
            sum+= n;
        }
        cout << sum << endl;
        cin >> s;
    }
    
    
    return 0;
}



Measured memory_bytes: 3192
#pragma GCC optimize ("03")
#pragma GCC target("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define sz(x) (ll)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define nl "\n"

const int mod=100000007;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	ll sum=0;
	for(int i=0;i<s.size();i++) {
		sum+=(s[i]-'0');
	}
	if(sum%9==0) {
		cout << "Yes";
	}else {
		cout << "No";
	}
}



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

int main() {
  int X,N;
  cin>>X>>N;
  vector<int> p(N);
  rep(i,N){cin >> p.at(i);}
  sort(p.begin(), p.end());
 
  vector<int> dum(102);  
  rep(i,102){dum.at(i)=i;}
  rep(i,N){dum.at(p.at(i))=10000;}
  
  int Ans,dif;
  Ans=X;
  dif=1000;
  
  rep(i,102){
  if(abs(dum.at(i)-X)<dif)
  {dif=abs(dum.at(i)-X);
   Ans=dum.at(i);}
  }
  cout<<Ans<<endl;  
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){ 
  char b; cin >> b;
  if(b=='A')cout << 'T' << ln;
  if(b=='T')cout << 'A' << ln;
  if(b=='C')cout << 'G' << ln;
  if(b=='G')cout << 'C' << ln;
}


Measured memory_bytes: 256
// 8/29 リアルタイム参加
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> R(N);  // R(0) = 0番目から右の総和、R(N-1) = N-1番目から右の総和
    R[N-1] = 0;
    for (int i = N-1; i > 0; i--) {
        R[i-1] = R[i] + A[i];
        R[i-1] %= mod;
    }

    ll ans = 0;

    for (int i = 0; i < N-1; i++) {
        ans += A[i] * R[i];
        ans %= mod;
    }

    cout << ans << endl;
}

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

const int N = 1e5 + 8;
int a[N];
int main()
{
	cin.sync_with_stdio(0);
	int tot = 0;
	int x; cin >> x;
	while (x)
	{
		a[++tot] = x % 10;
		x /= 10;
	}
	if (a[1] == a[2] && a[2] == a[3] || a[2] == a[3] && a[3] == a[4])
		cout << "Yes" << endl; 
	else cout << "No" << endl;
}


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

using namespace std;
typedef long long ll;

int main(void)
{
    int n;
    long long k;
    cin >> n >> k;
    vector<pair<int, int>> num(n);
    for (int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        num.at(i) = make_pair(a, b);
    }

    sort(num.begin(), num.end());
    long long sum = 0;
    int ans = num.at(0).first;
    for (int i = 0; i < n; i++){
            if (k <= sum){
                cout << ans << endl;
                return 0;
            }
            sum += num.at(i).second;
            ans = num.at(i).first;
    }
    cout << ans << endl;
    return 0;
}

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

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


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> a(n);

  int k = 0;
  for (int i = 0; i < n; i++) {
    cin >> k;

    for (int j = 0; j < k; j++) {
      int tmp;
      cin >> tmp;
      a[i].push_back(tmp);
    }
  }

  map<int, int> ma;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i].size(); j++) {
      ma[a[i][j]]++;
    }
  }
  int cnt = 0;
  for (auto r : ma) {
    if (r.second == n) { cnt++; }
  }
  cout << cnt << endl;
}

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

signed main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3]) {
        if (s[1] == s[2])
            cout << "No" << "\n";
        else
            cout << "Yes" << "\n";
    }
    else
        cout << "No" << "\n";
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    a = list(map(int, input().split()))

    n_1 = 0
    n_4 = 0
    for aa in a:
        if aa % 2 == 1:
            n_1 += 1
        elif aa % 4 == 0:
            n_4 += 1

    if n_1 + n_4 == N:
        ans = "Yes" if n_1 - 1 <= n_4 else "No"
    else:
        ans = "Yes" if n_1 <= n_4 else "No"
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    priority_queue<int> pq;
    for(int i = 0; i < n; i++){
        pq.push(a.at(i));
    }
    int t = 0;
    for(int i = 0; i < m; i++){
        t = pq.top();
        pq.pop();
        t = t / 2;
        pq.push(t);
    }
    long sum = 0;
    for(int i = 0; i < n; i++){
        sum = sum + pq.top();
        pq.pop();
    }
    cout << sum;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int v, e;
map <int , vector <int>> mp;
int dp[100000+1]={};
int calc(int i){
	if (dp[i]!=-1){
		return dp[i];
	}
	int ans=0;
	for (auto x : mp[i]) {
		ans=max(ans,calc(x)+1);
}
return dp[i]=ans;
}
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
// #ifndef ONLINE_JUDGE 
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout); 
// #endif
   	
   	cin >> v>>e;
   	
   	for (int i=1;i<=v;i++){
   		mp[i]={};
   	}
   	for (int i=0;i<1e5+1;i++){
   		dp[i]=-1;
   	}

   	for (int i=0;i<e;i++){
   		int sou,des;
   		cin>>sou>>des;
   		mp[des].push_back(sou);
   	}


	int ans=0;
	for (int i=0;i<v;i++){
   		ans=max(ans,calc(i+1));
   	}
   	cout <<ans;
	return 0;

}


Measured memory_bytes: 19072
#include <stdio.h>

int main()
{
  int i;
  int m, n;
  int total_payment;
  int money;
  int payment;
  
  while (1) {
    total_payment = 0;
    scanf("%d %d", &n, &m);
    if (m == 0 && n == 0) break;
    payment = m / n;
    for (i = 0; i < n; i++) {
      scanf("%d", &money);
      if (money >= payment) {
	total_payment += payment;
      } else {
	total_payment +=  money;
      }
    }
    printf("%d\n", total_payment);
  }

  return 0;
}



Measured memory_bytes: 2040
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] s = S.toCharArray();
        
        int ans = 0;
        for(int i = 1; i <= s.length-1; i++){
          if((s[i-1] == '0' && s[i] == '1')||(s[i] == '0' && s[i-1] == '1')){
            ans += 2;
            s[i-1] = '5';
            s[i] = '5';
          }
        }
      
         int count1 = 0;
         int count0 = 0;
         for(int i = 0; i < s.length; i++){
           if(s[i] == '1'){
             count1++;
           }else if(s[i] == '0'){
             count0++;
           }
         }
      
        if(count1 > count0){
          ans += count0*2;
        }else{
          ans += count1*2;
        }
          System.out.println(ans);
        
	}
}

Measured memory_bytes: 39708
#include<cstdio>
#include<algorithm>
int main(void){
  int x, y, a[5100], b[5100], ans = 0, k;
  scanf("%d %d", &x, &y);
  for(int i = 0;i < x; i++) scanf("%d", a + i);
  for(int i = 0;i < y; i++) scanf("%d", b + i);
  for(int i = 0;i < y; i++){
    k = 0;
    for(int j = 0;j < x; j++){
      if(a[j] == b[i + k]) k++;
    }
    ans = std::max(ans, k);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 1064
import sys
sys.setrecursionlimit(10*9)

n,m,k = map(int,input().split())
parent_of = [-1 for _ in range(n)]
#print(parent_of)
def root_of(x):
	if parent_of[x] < 0:
		return x
	else:
		parent_of[x] = root_of(parent_of[x])
		return parent_of[x]

def unite(x,y):
	top_root_x = root_of(x)
	top_root_y = root_of(y)
	if top_root_x == top_root_y:
		return False
	if parent_of[top_root_x] > parent_of[top_root_y]:
		top_root_x,top_root_y = top_root_y,top_root_x
	#print(parent_of[top_root_y])
	parent_of[top_root_x] += parent_of[top_root_y]
	parent_of[top_root_y] = top_root_x
	return True

def size_of(x):
		return -parent_of[root_of(x)]

def is_same(x,y):
	return root_of(x) == root_of(y)

friend_list = [-1] * n
for _ in range(m):
	a,b = map(int,input().split())
	a -= 1
	b -= 1
	friend_list[a] -=1
	friend_list[b] -=1
	unite(a,b)

for _ in range(k):
	c,d = map(int,input().split())
	c -= 1
	d -= 1
	if root_of(c) == root_of(d):
		friend_list[c] -= 1
		friend_list[d] -= 1
for i in range(n):
	friend_list[i] += size_of(i)
	#print(size_of(i))
print(*friend_list)


Measured memory_bytes: 13388
main = do
    putStrLn . show . solve =<< getLine

-- |
-- >>> solve "1234567876"
-- 34
-- >>> solve "35753"
-- 0
-- >>> solve "1111111111"
-- 642

solve :: String -> Int
solve = solve' 753 753
  where
    solve' u m s = case s of
        a:s'@(b:c:_)
            | n < m     -> solve' u n s'
            | otherwise -> solve' u m s'
          where
            n = abs $ u - read (a:b:c:[])
        _ -> m


Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	private int N;
	private List<int>[] adj;
	private int T;
	private int[] d;
	private int[] f;

	public void Solve()
	{
		N = GetInt();
		adj = Enumerable.Range(0, N).Select(_ => new List<int>()).ToArray();
		for(int i = 0; i < N; i++)
		{
			int u = GetInt() - 1;
			int K = GetInt();
			for(int j = 0; j < K; j++)
				adj[u].Add(GetInt() - 1);
		}

		T = 0;
		d = new int[N];
		f = new int[N];

		for(int i = 0; i < N; i++)
		{
			if(d[i] == 0)
				dfs(i);
		}

		for(int i = 0; i < N; i++)
			WriteLine($"{i + 1} {d[i]} {f[i]}");
	}

	private void dfs(int v)
	{
		d[v] = ++T;
		foreach(int u in adj[v])
		{
			if(d[u] == 0)
				dfs(u);
		}
		f[v] = ++T;
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}


Measured memory_bytes: 18440
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1e9 + 10;//10^9
ll MOD  = 1000000007;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};

int main(void){
    int N;
    cin >> N;
    vector<ll> s(N);
    for(int i = 0; i < N; i++) cin >> s[i];
    ll ans = 0;
    
    for(int C = 1; C <= N - 1; C++){
        set<int> visited;
        ll score = 0;
        for(int x = 0;; x++){
            int A = (N - 1) - x * C;
            if(A <= 0 || N <= A) break;
            if(A-C <= 0 || N <= A-C) break;//B =　A - C
            if(x*C == A) break;
            if(visited.count(x*C) || visited.count(A)) break;
            visited.insert(x*C);
            visited.insert(A);
            score += s[x * C];
            score += s[A];
            ans = max(ans, score);
        }
    }
    cout << ans << endl;
    
}



Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD_Q 1e9 + 7
#define MOD_A 998244353

 #define int long long



void solve()
{

  int N;
  cin>>N;
  vector<pair<int,int> > data;

  for (int i = 0; i < N; i++)
  {
    int A,B;
    cin>>A>>B;
    pair<int,int> P;
    P.first = B;
    P.second = A;
    data.push_back(P);
  }

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


  int Sum =0;
  int time = 0;
  int Limit = 0;

  for (int i = 0; i < N; i++)
  {
    Limit = data[i].first ;
    Sum += data[i].second;

    if(Sum > Limit)
    {
      cout<<"No"<<endl;
      return;
    }

    
    
  }
    cout<<"Yes"<<endl;
  
  

  
  
  
  
  return;
}
 
int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 6512
#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;
int main(){
	int N;
	int a;
	cin>>N;
	int res=0;
	unordered_map<int,int> numCount;
	for(int i=0;i<N;i++){
		cin>>a;
		numCount[a]++;
	}
	auto iter=numCount.begin();
	while(iter!=numCount.end()){
		if(iter->first==iter->second){
			iter++;
			continue;
		}
		else if(iter->first>iter->second){
                         res+=iter->second;
                         iter++;
                 }
			
		else{
                     res+=iter->second-iter->first;
                      iter++;
                       }
			
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 4260
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    map<string,int> a;
    a["AC"] = 0;
    a["WA"] = 0;
    a["TLE"] = 0;
    a["RE"] = 0;
    rep(i,0,n){
        string x;cin>>x;
        a[x]++;
    }
    cout<<"AC x "<<a["AC"]<<endl;
    cout<<"WA x "<<a["WA"]<<endl;
    cout<<"TLE x "<<a["TLE"]<<endl;
    cout<<"RE x "<<a["RE"]<<endl;
}

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
int nowp[1100],ask[4400],to[200100];
bool ans1[200100],ans2[200100];
vector<int>G[1100];
int main() {
	int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int a;
		scanf("%d%d",&a,&to[i]);
        G[a].push_back(i);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) nowp[j] = 0;
        int s=1,t=0;
        for(int p=0;p<G[i].size();p++) nowp[ask[++t]=to[G[i][p]]]=G[i][p];
        while(s<=t) {
            int x=ask[s++],y=nowp[x];
            for(int p=0;p<G[x].size();p++) {
                int q = to[G[x][p]];
                if(q!=i){
                	if(nowp[q]!=-1){
                		if(nowp[q]==0) nowp[ask[++t]=q]=y;
                   		else if(nowp[q]!=y) nowp[ask[++t]=q]=-1;
					}
                }
                else ans1[G[x][p]] = 1;
            }
        }
        for(int p=0;p<G[i].size();p++)
			if(nowp[to[G[i][p]]]==-1) ans2[G[i][p]]=1;
    }
    for(int i=1;i<=m;i++){
    	if(ans1[i]==ans2[i]) puts("same");
    	else puts("diff");
	}
}

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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

signed main(){
	int n=read();
	vi cnt(3,0);
	REP(i,n){
		int x=read();
		if(x%4==0)cnt[2]++;
		else if(x%2==0)cnt[1]++;
		else cnt[0]++;
	}
	if(cnt[1])cnt[0]++;
	if(cnt[0]<=cnt[2]+1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	char n[2];
	int i;
	scanf("%s",n);
	for(i=0;i<2;i++){
		if(n[i]=='9'){
			printf("Yes\n");
			break;
		}
	}
	if(i==2)  printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

const int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
//const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int h, w;
	cin >> h >> w;
	vs fld(h);
	REP(i, h) cin >> fld[i];
	int sx, sy;
	REP(i, h)REP(j, w)
	{
		if (fld[i][j] == '%')
		{
			sx = i; sy = j;
		}
	}
	int pr = INF, so = INF;
	queue<pii> que;
	que.emplace(sx, sy);
	vector<vi> dist(h, vi(w, INF));
	dist[sx][sy] = 0;
	while (!que.empty())
	{
		int x = que.front().first;
		int y = que.front().second;
		que.pop();
		if (fld[x][y] == '@') chmin(pr, dist[x][y]);
		if (fld[x][y] == '$') chmin(so, dist[x][y]);
		REP(i, 4)
		{
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (!valid(nx, ny, h, w) || fld[nx][ny] == '#' || dist[nx][ny] < INF) continue;
			dist[nx][ny] = dist[x][y] + 1;
			que.emplace(nx, ny);
		}
	}
	cout << (pr < so ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード

//ループ
#define REP(i, n) for(int i = 0; i < n; i++) //普通のループ
#define REPR(i, n) for(int i = n; i >= 0; i--) //逆ループ
#define FOR(i, m, n) for(int i = m; i < n; i++) //最初の数値を指定したループ

//型名省略
typedef long long ll;

//配列要素数
static const int MAX = 200000;

using namespace std;

//#include "./lib/string.h"

int main(){
    ll n, R[MAX];

    cin >> n;
    REP(i, n) cin >> R[i];

    ll maxv = -2000000000;
    ll minv = R[0];

    FOR(i, 1, n){
        maxv = max(maxv, R[i]-minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

    return 0;

    return 0;
}


Measured memory_bytes: 4648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i,j,x,y,f,c = 1,ans = 0;scanf("%d%d",&n,&m);
  int p[n],g[n] = {};vector<int> v[n];queue<int> q;
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);p[i]--;
  }
  for(i=0;i<m;i++){
    scanf("%d%d",&x,&y);x--;y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for(i=0;i<n;i++){
    if(g[i]!=0) continue;
    queue<int>().swap(q);q.push(i);
    while(!q.empty()){
      f = q.front();q.pop();
      g[f] = c;
      for(j=0;j<v[f].size();j++){
        if(g[v[f][j]]==0) q.push(v[f][j]);
      }
    }
    c++;
  }
  for(i=0;i<n;i++) ans += g[i] ==g[p[i]];
  printf("%d\n",ans);
}

Measured memory_bytes: 6528
import java.io.*;

class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while((str = in.readLine()) != null){
			StringBuffer reverse = new StringBuffer().append(str);
			System.out.print(reverse.reverse() + "\n");
		}
		
	}
}

Measured memory_bytes: 16864
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

const int non = 10000000;

struct edge {
	int x, y, f, c, r;
};
vector<edge> E[202];

void add(int x, int y, int f, int c) {
	int p = E[x].size(), q = E[y].size();
	E[x].push_back({ x, y, f, c, q });
	E[y].push_back({ y, x, 0, -c, p });
}

int N, M, P, s, t;
vector<int> last_dist;

int spfa(){
	vector<int> dist(N, non), viax(N), viap(N);
	vector<bool> chk(N);
	priority_queue<pair<int, int> > qu;
	qu.push({ 0, s }); dist[s] = 0;
	while (!qu.empty()) {
		int c = -qu.top().first, x = qu.top().second; qu.pop();
		if (dist[x] < c) continue;
		int p = 0;
		for (auto &e : E[x]) {
			if (e.f) {
				int y = e.y, nc = c + e.c + last_dist[y] - last_dist[x];
				if (dist[y] > nc) {
					qu.push({ -nc, y });
					dist[y] = nc;
					viax[y] = x;
					viap[y] = p;
				}
			}
			p++;
		}
	}

	if (dist[t] == non) return 0;
	int ret = dist[t] - last_dist[t] + last_dist[s];
	last_dist = dist;
	int y = t;
	while (y != s) {
		int x = viax[y];
		auto &e = E[x][viap[y]];
		e.f--;
		E[y][e.r].f++;
		y = x;
	}
	return ret;
}

int main(){
	scanf("%d %d %d %d %d", &N, &M, &P, &s, &t);
	s--; t--;

	for (int i = 0; i < M; i++) {
		int x, y, d, c;
		scanf("%d %d %d %d", &x, &y, &d, &c); x--; y--;
		add(x, y, c, d);
	}

	int sum = 0, flow = 0; double ans = 1e10;
	last_dist = vector<int>(N, non);
	while (1) {
		int now = spfa();
		if (now == 0) break;
		sum += now; flow++;
		ans = min(ans, 1. * (sum + P) / flow);
	}
	printf("%.12lf\n", ans);
}



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

def main():
    N,C = map(int,input().split())
    D = [list(map(int,input().split())) for _ in range(C)]
    c = [list(map(int,input().split())) for _ in range(N)]
    mod_0 = [0 for _ in range(C)]
    mod_1 = [0 for _ in range(C)]
    mod_2 = [0 for _ in range(C)]
    for i in range(N):
        for j in range(N):
            if (i+j)%3 == 0:
                mod_2[c[i][j]-1] += 1
            if (i+j)%3 == 1:
                mod_0[c[i][j]-1] += 1
            if (i+j)%3 == 2:
                mod_1[c[i][j]-1] += 1
    INF = 10**10
    ans = INF
    for i in range(C):
        for j in range(C):
            if i == j:
                continue
            for k in range(C):
                if i == k or j == k:
                    continue
                ans = min(ans,sum(mod_0[n]*D[n][i] for n in range(C))+\
                              sum(mod_1[n]*D[n][j] for n in range(C))+\
                              sum(mod_2[n]*D[n][k] for n in range(C)))
    print(ans)

if __name__ == "__main__":
    main()

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

#define F first
#define S second
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define bpp(x) __builtin_popcount(x)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front

using namespace std;
using ll = long long;
using dl = double;
using ull = unsigned long long;

const int N = (int)1e5 + 5;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 18;

int n,a[105];

bool can[10005];

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	can[0] = 1;
	for(int i = 1; i <= n; i++){
		for(int cur = 10000 - a[i]; cur >= 0; cur--){
			if(can[cur]) can[cur + a[i]] = 1;
		}
	}
	for(int i = 10000; i >= 1; i--){
		if(i % 10 == 0) continue;
		if(can[i]){
			cout << i;
			return 0;
		}
	}
	cout << 0;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define inf (long long)(1e18 + 1)
using namespace std;

long long n, k;
vector<long long> c, p;

long long solve();

int main() {
  cin >> n >> k;
  p.resize(n);
  for (auto& x : p) {
    cin >> x;
    --x;
  }
  c.resize(n);
  for (auto& x : c) cin >> x;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = -inf;
  for (int i = 0; i < n; ++i) res = max(res, c[p[i]]);
  for (int i = 0; i < n; ++i) {
    vector<bool> ch(n, 0);
    vector<int> v(1, i);
    ch[i] = 1;
    int now = i, cnt = 0;
    long long sum = 0;
    while (cnt < k) {
      now = p[now];
      sum += c[now];
      v.push_back(now);
      res = max(res, sum);
      ++cnt;
      if (ch[now]) break;
      ch[now] = 1;
    }
    if (cnt == k) continue;
    int ls = now;
    long long loops = c[now], lcnt = 1;
    v.pop_back();
    while (v.back() != ls) {
      loops += c[v.back()];
      v.pop_back();
      ++lcnt;
    }
    if (loops >= 0) {
      long long pls = max((k - cnt) / lcnt - 1, 0LL);
      cnt += pls * lcnt;
      sum += loops * pls;
    }
    cnt = max((long long)cnt, k - 3 * n);
    res = max(res, sum);
    while (cnt < k) {
      now = p[now];
      sum += c[now];
      res = max(res, sum);
      ++cnt;
    }
  }
  return res;
}


Measured memory_bytes: 3644
from collections import deque

# print('input >>')
N, M = map(int,(input().split()))
ABs = [map(int,(input().split())) for _ in range(M)]

INF = 10 ** 10
ds = [INF] * (N+1)
marks = [0] * (N+1)

nodes = [None] * (N+1)

for AB in ABs:
    A, B = AB
    if nodes[A] is None:
        nodes[A] = []
    nodes[A].append(B)

    B, A = A, B
    if nodes[A] is None:
        nodes[A] = []
    nodes[A].append(B)

# print(nodes)

queue = deque([1])
visited = [0] * (N+1)
visited[1] = 1

# d = 0
# ds = [INF] * (N+1)
marks = [0] * (N+1)
parent = 1

while len(queue) > 0:
    p = queue.popleft()
    # print(p)
    # parent, node = p[0], p[1]
    # visited[node] = 1
    # marks[node] = parent
    for n in nodes[p]:
        if visited[n] == 0:
            visited[n] = 1
            marks[n] = p
            queue.append(n)

print('Yes')
for mark in marks[2:]:
    print(mark)


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

using namespace std;
using ll =long long;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	vector<vector<int>> a(3,vector<int>(3));
	rep(i,3) rep(j,3) cin >> a[i][j] ;
	int n;
	cin >> n;
	int b[n] ;
	rep(i,n) cin >> b[i]; 

	rep(i,n){
		int now = b[i] ;
		rep(j,3){
			rep(k,3){
				if(now == a[j][k]){
					a[j][k] = -1 ; //あったよ
				}
			}
		}
	}
	rep(i,3){
		if(a[i][0]==a[i][1] && a[i][1] ==a[i][2]){
			puts("Yes");
			return 0;
		}
	}
	rep(i,3){
		if(a[0][i]==a[1][i] && a[1][i] ==a[2][i]){
			puts("Yes");
			return 0;
		}
	}
	if(a[0][0]==a[1][1] && a[1][1] ==a[2][2]){
		puts("Yes");
		return 0;
	}
	if(a[0][2]==a[1][1] && a[2][0] ==a[1][1]){
		puts("Yes");
		return 0;
	}
	puts("No");
	return 0 ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;


signed main(){
  int x,y;
  cin>>x>>y;
  int len=0;
  while(x<=y){
    len++;
    x*=2;
  }
  cout<<len<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define LINF (1LL << 60)
#define MOD (1000000007)
using namespace std;
typedef long long Int;

int h, w;
string fld[1100000];
string row;
int dist[1100000];

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> row;
    for (int j = 0; j < w; j++) {
      fld[i * w + j] = row[j];
    }
  }

  dist[0] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int v = i * w + j;
      if (fld[v] == "#") continue;
      if (0 <= j - 1) dist[v] += dist[i * w + j - 1];
      if (0 <= i - 1) dist[v] += dist[(i - 1) * w + j];
      dist[v] %= MOD;
    }
  }

  cout << dist[h * w - 1] << endl;
  return 0;
}

Measured memory_bytes: 41928
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[55][55];
int n,m;
int mov[8][2]={{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,-1}};
inline bool checkoutofmap(int x,int y){
	if(x<=0||y<=0||x>n||y>m)return true;
	return false;
}
int main(){
	cin>>n>>m;
	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)
			if(a[i][j]=='.'){
				int cnt(0);
				for(int k=0;k<8;++k){
					int tmpx(i+mov[k][0]),tmpy(j+mov[k][1]);
					if(checkoutofmap(tmpx,tmpy)||a[tmpx][tmpy]!='#')continue;
					++cnt;
				}
				a[i][j]=cnt+'0';
			}
	for(int i=1;i<=n;++i,cout<<endl)
		for(int j=1;j<=m;++j)
			cout<<a[i][j];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,1};
const int dy[6] = {0, 1, 0, -1,1,-1};
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; }
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    vector<int> cnt(N,0);
    vector<vector<int>> S(N+1,vector<int> (M,0));
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i]--;
        cnt[A[i]]++;
        for(int j=0; j<M; j++){
            S[i+1][j] += S[i][j] + (A[i] == j);
        }
    }
    vector<ll> dp(1LL<<M,inf);
    dp[0] = 0;
    for(int bit=0; bit<(1LL<<M); bit++){
        int sum = 0;
        for(int i=0; i<M; i++){
            if(bit & (1LL<<i)) sum += cnt[i];
        }
        for(int i=0; i<M; i++){
            if(bit & (1LL<<i)) continue;
            int nbit = bit | (1LL<<i);
            int res = cnt[i] - (S[sum+cnt[i]][i] - S[sum][i]);
            chmin(dp[nbit],dp[bit]+res);
        }
    }
    // for(int i=0; i<(1LL<<M); i++){
    //     cout << "check: " << i << " " << dp[i] << enld;
    // }
    cout << dp[(1LL<<M)-1] << enld;
    return 0;
}


Measured memory_bytes: 23368
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int[][] op = new int[][]{{1,1,1},{1,1,-1},{1,-1,1},{-1,1,1},{-1,-1,1},{-1,1,-1},{1,-1,-1},{-1,-1,-1}};
        int[] a = new int[4];
        for(int i=0;i<4;i++){
            a[i] = S.charAt(i)-'0';
        }
        String[] dic = new String[]{"-"," ","+"};
        for(int i=0;i<8;i++){
            int[] cur = op[i];
            int res = a[0]+a[1]*cur[0]+a[2]*cur[1]+a[3]*cur[2];
            if(res == 7){
                StringBuilder sb = new StringBuilder();
                sb.append(a[0]);
                sb.append(dic[cur[0]+1]);
                sb.append(a[1]);
                sb.append(dic[cur[1]+1]);
                sb.append(a[2]);
                sb.append(dic[cur[2]+1]);
                sb.append(a[3]);
                sb.append("=7");
                System.out.println(sb.toString());
                System.exit(0);
            }
        }
    }
}


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

int main() {
  string s,t;cin>>s>>t;
  rep(i,s.size()){
    s=s.substr(1)+s[0];
  if(s==t){
    cout<<"Yes"<<endl;
    return 0;
  }
  }
  cout<<"No"<<endl;
}
  

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n;
    cin >> n;
    long long a[n];
    unordered_map<long long, long long> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
    }
    long long ans = 0;

    for (auto p : mp) {
        ans += (p.second * (p.second - 1)) / 2;
    }
    vector<long long> v;
    for (int i = 0; i < n; i++) {
        long long c = mp[a[i]] - 1;
        v.push_back(ans - c);
    }
    for (auto a : v) {
        cout << a << endl;
    }
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int a[4];
    for(int i=0;i<4;i++) a[i]=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='N') a[0]++;
        else if(s[i]=='W') a[1]++;
        else if(s[i]=='S') a[2]++;
        else if(s[i]=='E') a[3]++;
    }
    string ans="Yes";
    if(a[0]*a[2]==0&&a[0]+a[2]>0) ans="No";
    if(a[1]*a[3]==0&&a[1]+a[3]>0) ans="No";
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;

    cin >> n;
    for(int i = 0; i < n; i++) {
      cin >> R[i];
    }
    
    int maxv = -1000000000;
    int minv = R[0];
    
    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i] - minv);
        minv=min(minv,R[i]);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3868
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<bitset>
// #include<unordered_map> 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// #include "boost/algorithm/string.hpp"
#define fio ios_base::sync_with_stdio(false)
#define mod 1000000007
#define mod1 mod
#define mod2 100000009
#define li long long int
#define ll int
#define readi(x) scanf("%d",&x)
#define  reads(x)  scanf("%s", x)
#define readl(x) scanf("%I64d",&x)
#define rep(i,n) for(i=0;i<n;i++)
#define revp(i,n) for(i=(n-1);i>=0;i--)
#define myrep1(i,a,b) for(i=a;i<=b;i++)
#define myrep2(i,a,b) for(i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define MAXN 1000000000000000000
#define MINN -1000000000000000000
#define pii pair<ll,ll> 
#define pdd pair<double,double>
#define pic pair<int,char>
#define N 200100
#define lgn 20
#define ddouble long double
#define minus minu
#define PI 3.1415926535
#define lgn 20


// #define INTMAX 200000000

// using namespace boost;
// #define si short int

using namespace std;
using namespace __gnu_pbds;             
// typedef priority_queue<ll, vector<ll> > max_pq;
// typedef priority_queue<pii, vector<pii> , greater<pii >  > min_pq;
ll toint(const string &s) {stringstream ss; ss << s; ll x; ss >> x; return x;}
string tostring ( ll number ){stringstream ss; ss<< number; return ss.str();}

// typedef priority_queue<pair < ll , pair < pii , ll > >  , vector<pair < ll , pair < pii , ll > >  > ,greater<pair < ll , pair < pii , ll > >  > > min_pq;

typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
typedef priority_queue< pii , vector<pii> > max_pq;
typedef priority_queue<pii, vector<pii> , greater <pii>  > min_pq;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ll n;
    cin >> n;
    ll cnt = 0;
    while(n)
    {
        if (n%10 == 9 )
            cnt++;
        n/=10;
    }
    if ( cnt )
        cout <<"Yes";
    else
        cout <<"No";












}                       

Measured memory_bytes: 256
import math
N, P = map(int, input().split())
A = list(map(int, input().split()))
div = 0
for a in A:
  if a % 2 == 1:
    div += 1

ans = 0
mlt = 2 ** (N-div)
if P == 0:
  for i in range(0, div+1, 2):
    cmb = math.factorial(div) // (math.factorial(div-i) * math.factorial(i))
    ans += cmb * mlt
else:
  for i in range(1, div+1, 2):
    cmb = math.factorial(div) // (math.factorial(div-i) * math.factorial(i))
    ans += cmb * mlt
    
print(ans)

Measured memory_bytes: 9216
import Control.Monad (replicateM)
main = do
  [n,m,c] <- map read . words <$> getLine
  bn <- map read .words <$> getLine
  anm <- replicateM n $ map read . words <$> getLine::IO[[Int]]
  print $ length $ filter (>0) [foldl (\acc (a, b) -> acc + a * b) c $ zip am bn |am <- anm]

Measured memory_bytes: 1020
import sys
INF = (sys.maxint)/3

def MaximumProfit(R_list):
	minR = INF
	maxD = -INF
	for R in R_list:
		maxD = max(maxD, R - minR)
		minR = min(minR, R)
	return maxD

def main():
	n = input()
	R_list = []
	for i in range(n):
		R_list.append(input())
	print MaximumProfit(R_list)

if __name__ == '__main__':
	main()

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

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

		//??????t????????????????????????????????°??£????????????
		int runningTrain[3600*24]={0};

		for(int i=0; i<n; ++i){
			int ah, am, as; //arrival
			int lh, lm, ls; //leave;

			scanf(" %d:%d:%d %d:%d:%d", &lh, &lm, &ls, &ah, &am, &as);

			int arrival = ah*3600+am*60+as;
			int leave = lh*3600+lm*60+ls;
			runningTrain[leave]++;
			runningTrain[arrival]--;
		}

		int ans=runningTrain[0];
		for(int i=0; i<3600*24-1; ++i){
			runningTrain[i+1] += runningTrain[i];
			ans = max(ans, runningTrain[i+1]);
		}

		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1536