akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
char a[110],b[110];
int la,lb;
void wrong(){
	cout<<"No";
	exit(0);
}

void right(){
	cout<<"Yes";
	exit(0);
}
bool pd(int h){
	for(int i=0;i<la;i++){
		if(a[i]!=b[(i+h)%lb])
		  return 0;
	}
	return 1;
}
int main(){
	cin>>a>>b;
	la=strlen(a);
	lb=strlen(b);
	if(la!=lb)
		wrong();
	for(int i=0;i<lb;i++)
		if(pd(i))
		  right();
	wrong();
}

Measured memory_bytes: 256
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
    public static long mod = (long) (1e9+7);
    public final static int MAX = (int) 90000000;
  // static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
	   
	 FastReader sc = new FastReader();
	 char[] s = sc.next().toCharArray();
	 int b = 0;
	 long ans = 0;
	 for(int i=0;i<s.length;++i) {
		 if(s[i] == 'B') ++b;
		 else ans += b;
	 }
	 out.print(ans);
	 out.close();
		
	}

}

Measured memory_bytes: 25300
N = int(input())
A = list(map(int,input().split()))
A.sort()
M = 10**6+5
cnt = [0]*M
for x in A:
    if cnt[x] != 0:
        cnt[x] = 2
        continue
    for i in range(x,M,x):
        cnt[i] += 1
ans = 0
for i in A:
    if cnt[i] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 32208
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;
const int N=300010;
int n,a[N];
bool vis[N];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	int ans=0;
	for (int i=30;i>=0;i--)
	{
		int j=n,k=1;
		while (j>=1)
		{
			if (vis[j]) { j--;continue;}
			while (k<j)
			{
				if (a[j]+a[k]>(1<<i)) break;
				if (!vis[k]&&a[j]+a[k]==(1<<i)) { vis[j]=vis[k]=1;ans++;break;}
				k++;
			}
			j--;
		}
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(int argc, char** argv) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);


    int n;
    cin >> n;
    vector<int> xs(n), ys(n), hs(n);
    for(int i=0; i<n; i++){
        cin >> xs[i] >> ys[i] >> hs[i];
    }

    for(int cx = 0; cx <= 100; cx++){
        for(int cy = 0; cy <= 100; cy++){
            bool ok = 1;
            int H = -1;
            int hupper = 2e9;
            for(int i=0; i<n && ok; i++){
                int dist = abs(xs[i]-cx)+abs(ys[i]-cy);
                if (hs[i]){
                    int hcand = hs[i] + dist;
                    if (H==-1)
                        H = hcand;
                    else{
                        if (H!=hcand){
                            ok = 0;
                        }
                    }
                }
                else{
                   hupper = min(hupper, dist);
                }
            }

            if (ok && H <= hupper){
                cout << cx << " " << cy << " " << H;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e9+9;
 
ll power(ll a, ll b, ll m = mod) {
    ll x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
 
mt19937_64 gen (random_device{}());
ll rint(ll a, ll b) { // generate rand int in [a, b]
    return a + gen() % (b - a + 1);
}
long long score(int a, int j) {
    if(j == 0 || j == 4) return a;
    if(j == 1 || j == 3) {
        if(a == 0) return 2;
        return (a & 1);
    }
    return (~a & 1);
}
const int N = 2e5+9;
long long f[N][5], a[N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n; cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= 4; j++) {
            f[i][j] = 2e18;
        }
    }
    // f[0][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < 5; j++) {
            f[i][j] = min((j?f[i][j-1]:inf), f[i-1][j] + score(a[i], j));
        }
    }
    /*for(int i = 1; i <= n; i++) {
        cout << i << ": ";
        for(int j = 0; j <= 4; j++) {
            cout << f[i][j] << " ";
        }
        cout << endl;
    }*/
    cout << f[n][4] << endl;







    return 0;
    
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define endl "\n"
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000 , mod = 1000000007;
#define PI 3.14159265
int main()
{
    fastio;
    string s;
    cin>>s;
    if(s=="ABC")
    cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
    return 0;
}

Measured memory_bytes: 3632
a, b, c, x, y = map(int, input().split())
if a + b <= 2 * c:
    ans = a * x + b * y
elif x < y:
    ans = min(
        2 * c * x + b * (y - x), 2 * c * y
    )
elif y <= x:
    ans = min(
        2 * c * y + a * (x - y), 2 * c * x
    )
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    string S;
    cin >> S;
    for (int i = 0; i < S.size() - 1; i++){
        if (S.at(i) == 'A' && S.at(i + 1) == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

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

int main() {

    ll N;
    vector<ll> A;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        A.push_back(a);
    }

    int x;
    sort(A.begin(),A.end());
    for (int i = 0; i < N; ++i) {
        ll a = A[i];
        if(i == 0){
            x = a;
        }else{
            ll t = gcd(x, a);
            x = t;
        }
    }

    cout << x << endl;
    
    return 0;
}

Measured memory_bytes: 1400
// ராஜ்_ஆர்ட்டன்

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

void solve() {
	
	char ch;
	cin >> ch;
	
	if('a' <= ch && ch <= 'z') cout << "a" << endl;
	else cout << "A" << endl;
	
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0);
	// int t; cin >> t; for(int i = 1; i <= t; i++) //cout << "Case #" << i << ": ",
	solve();
	return 0;
}


Measured memory_bytes: 3648
n,m = map(int,input().split())
h = list(map(int,input().split()))
p = [0 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] >= h[b-1]:
        p[b-1] = -1
    if h[a-1] <= h[b-1]:
        p[a-1] = -1
print(p.count(0))

Measured memory_bytes: 20104
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) puts("error")
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=993244853;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;GG(e<0);
        while(e){if(e&1)ans=ans*x%MOD;x=x*x%MOD;e>>=1;}
        return ans;
    }
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e5+10;

    char str[N];
    void main()
    {
        scanf("%s",str+1);
        int n=strlen(str+1);
        for(int i=1;i<=n;i++)
        {
            if(i&1){if(str[i]=='L'){puts("No");return;}}
            else {if(str[i]=='R'){puts("No");return;}}
        }
        puts("Yes");
    }//(ans+MOD)%MOD
};
int main()
{
    srand(time(0));
    mine::main();
}


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

int main()
{
  char s;
  cin >> s;

  if (s == 'a' || s == 'i' || s == 'u' || s == 'e' || s == 'o')
  {
    cout << "vowel" << endl;
  }

  else
  {
    cout << "consonant" << endl;
  }
}


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

int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  long long ans=0;
  ans = max(max(a*c,b*d),max(a*d,b*c));
  cout << ans << endl;
  return 0;
}  

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

typedef long long ll;

template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& v) {
  if (!v.empty()) {
    out << '[';
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}
template <class T, class U>
void chmin(T& t, U f) {
  if (t > f) t = f;
}
template <class T, class U>
void chmax(T& t, U f) {
  if (t < f) t = f;
}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) {}
  UnionFind(const UnionFind& u) { data = u.data; }
  bool unionSet(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int N;
vector<int> x, y;
map<pair<int, int>, vector<pair<int, int>>> m;

void hoge(int i, int j) {
  //-2x(x2-x1)-2y(y2-y1)+()+()
  ll a = -2 * (x[j] - x[i]);
  ll b = -2 * (y[j] - y[i]);
  ll c = (x[j] * x[j] - x[i] * x[i]) + (y[j] * y[j] - y[i] * y[i]);
  for (int k = 0; k < N; ++k) {
    for (int l = k + 1; l < N; ++l) {
      if (abs(a * x[l] + b * y[l] + c) == abs(a * x[k] + b * y[k] + c) &&
          (x[k] - x[l]) * (y[i] - y[j]) == (y[k] - y[l]) * (x[i] - x[j])) {
        m[{i, j}].push_back({k, l});
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  x.resize(N), y.resize(N);
  for (int i = 0; i < N; ++i) cin >> x[i] >> y[i];

  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      hoge(i, j);
    }
  }

  UnionFind start(N);
  vector<pair<UnionFind, int>> dp;
  dp.push_back({start, 0});
  int mi = N;
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      vector<pair<UnionFind, int>> v;
      for (auto& p : dp) {
        if (p.first.findSet(i, j)) continue;
        UnionFind next(p.first);
        for (auto& q : m[{i, j}]) {
          next.unionSet(q.first, q.second);
        }
        for (int k = 1; k < N; ++k) {
          if (!next.findSet(0, k)) {
            v.push_back({next, p.second + 1});
            break;
          }
          if (k == N - 1) chmin(mi, p.second + 1);
        }
      }
      for (auto& q : v) {
        dp.push_back(q);
      }
    }
  }
  cout << mi << endl;
}

Measured memory_bytes: 48364
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
 
using namespace std;
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
 

int main()
{
    int n;
    cin>>n;
    map <string,int> m;
    map <int,vector<string> > m2;
    map <string,int>::reverse_iterator it;
    map <string,int>::iterator it3;
    string s;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        m[s]+=1;
    }
    vector <string> row;
    for(it3=m.begin();it3!=m.end();it3++)
    {
        if(m2.find(it3->second)==m2.end())
            m2[it3->second]=row;
        m2[it3->second].push_back(it3->first);
    }
    set <string> s1;
    set <string>::iterator it2;
    row=(m2.rbegin()->second);
    for(int i=0;i<row.size();i++)
        s1.insert(row[i]);
    for(it2=s1.begin();it2!=s1.end();it2++)
        cout<<*it2<<endl;


    return 0;   
}
 
 

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

int main(){
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == 'o') counter++;
    if (s[1] == 'o') counter++;
    if (s[2] == 'o') counter++;
    cout << counter*100 + 700 <<endl;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//Black Force
public class Main{

	int h, w, c, val;
	int[][] a, d = {{-1,0},{0,1},{1,0},{0,-1}};
	boolean res, valid;
	boolean[][] v, b;

	void f(int L){
		v = new boolean[h][w];
		for(int i=1;i<h-1;i++)for(int j=1;j<w-1;j++){
			if(!v[i][j]&&a[i][j]<L){
				valid = true;
				val = 0;
				dfs(i, j, L);
				if(valid&&c<=val){
					res = true; return;
				}
			}
		}
	}

	void dfs(int i, int j, int L){
		if(v[i][j]||L<=a[i][j])return;
		v[i][j] = true;
		val += L-a[i][j];
		if(b[i][j]||i==0||i==h-1||j==0||j==w-1)valid = false;
		for(int k=0;k<4;k++){
			int ni = i+d[k][0], nj = j+d[k][1];
			if(0<=ni&&ni<h&&0<=nj&&nj<w)dfs(ni, nj, L);
		}
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			h = sc.nextInt(); w = sc.nextInt(); c = sc.nextInt();
			int r = sc.nextInt();
			if((h|w|c|r)==0)break;
			a = new int[h][w];
			Set<Integer> set = new HashSet<Integer>();
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				int x = sc.nextInt();
				a[i][j] = x;
				set.add(x);
			}
			b = new boolean[h][w];
			while(r--!=0){
				b[sc.nextInt()-1][sc.nextInt()-1] = true;
			}
			res = false;
			for(int x:set){
				if(res)break;
				f(x);
			}
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				if(res)break;
				if(b[i][j])continue;
				a[i][j]++;
				f(a[i][j]);
				a[i][j]--;
			}
			System.out.println(res?"Yes":"No");
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main() {
  string n;
  cin >> n;
  
  for (int i=0; i<3; i++){
    if (n.at(i) == '9') n.at(i) = '1';
    else n.at(i) = '9';
  }
  
  cout << n << endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc165/tasks/abc165_f

//参考：
//https://kmjp.hatenablog.jp/entry/2020/05/02/0930

//ポイント：
// 再帰(){
// 	なんか変更
// 	再帰();
// 	変更を戻す
// }
//とすると状態をさかのぼりながら処理が可能

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200001];
vector<vector<LL>> adj;

vector<LL> ans;

vector<LL> LIS_array;
bool used[200001] = {};
void dfs(LL now){
	used[now] = 1;
	bool pop_flag = false;
	int insert_index = int(lower_bound(LIS_array.begin(),LIS_array.end(),A[now])-LIS_array.begin());
	LL prev_num;

	if(insert_index==LIS_array.size()){
		pop_flag = true;
		LIS_array.push_back(A[now]);
	}else{
		prev_num = LIS_array[insert_index];
		LIS_array[insert_index] = A[now];
	}

	ans[now] = LIS_array.size();

	// cout << now << endl;
	// for(int i=0;i<LIS_array.size();i++) cout << LIS_array[i] << " ";
	// cout << endl;

	for(LL next:adj[now]){
		if(used[next]) continue;
		//cout << now << "->" << next << endl;
		dfs(next);
		//cout << now << "<-" << next << endl;
	}

	if(pop_flag) LIS_array.pop_back();
	else LIS_array[insert_index] = prev_num;
}

void solve(){
	ans = vector<LL>(N+1);
	dfs(1);
}

int main(){
    cin >> N;
    for(int i=1;i<=N;i++) cin >> A[i];
    adj = vector<vector<LL>>(N+1);
	for(int i=0;i<=N-2;i++){
		LL u,v;cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

    solve();

    for(int i=1;i<=N;i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 28456
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n+1);
    rep(i,n+1)cin>>a[i];
    vi b(n);
    rep(i,n)cin>>b[i];
    int ans=0;
    rep(i,n){
        int m=min(a[i],b[i]);
        ans+=m;
        b[i]-=m;
        m=min(a[i+1],b[i]);
        ans+=m;
        a[i+1]-=m;
    }
    cout<<ans<<endl;
}

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

int main () {
  int h, n, a = 0;
  string ans = "No";
  cin >> h >> n;
  
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    a += b;
  }
  if (a >= h) {
    ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll N;cin >> N;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    ll ans = 0;
    unordered_map<int, int> mp;
    for(int i = 0; i < N; i++){
        mp[A[i]/2]++;
    }
    bool flag = 1;
    if(N % 2 == 0){
        for(int i = 0; i < N / 2; i++){
            if(mp[i] != 2){
                flag = 0;
                break;
            }
        }
    }else{
        for(int i = 1; i <= N / 2; i++){
            if(mp[i] != 2){
                flag = 0;
                break;
            }
        }
        if(mp[0] != 1) flag = 0;
    }
    if(flag == 0) cout << 0 << endl;
    else{
        cout << modpow(2, N/2, MOD) << endl;
    }

}

Measured memory_bytes: 3084
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char ch[30];
char ch1[30];
int num[30];
int main(){
	int i,j;
	scanf("%s",ch);
	int len=strlen(ch),fl=1;
	memset(num,0,sizeof(num));
	for(i=0;i<len;i++){
		int temp=ch[i]-'a';
		if(num[temp]){
			fl=0;break;
		}
		num[temp]=1;
	}
	if(!fl){
		printf("-1\n");return 0;
	}
	if(len==26){
		int flag=1;
		for(i=0;i<len-1;i++){
			if(ch[i]<ch[i+1]){
				flag=0;break;
			}
		}
		if(flag) printf("-1\n");
		else{
			for(i=0;i<len;i++) ch1[i]=ch[i];
			if(next_permutation(ch1,ch1+len)){
				for(i=0;i<len;i++){
					printf("%c",ch1[i]);
					if(ch[i]!=ch1[i]) break;
				}
			}
		}
	}
	else{
		printf("%s",ch);
		for(i=0;i<26;i++){
			if(!num[i]){
				printf("%c\n",i+'a');
				break;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 128
import fractions
import numpy as np
import os
import sys

A,B,C,D=map(int,input().split())

E=C*D//fractions.gcd(C,D)

A0=A//C
B0=B//C
if(A%C==0):
    B0+=1
C0=B0-A0


A1=A//D
B1=B//D
if(A%D==0):
    B1+=1
D1=B1-A1

A2=A//E
B2=B//E
if(A%E==0):
    B2+=1
E2=B2-A2

if(C==1 or D==1):
    print(0)
else:
    print(int((B-A+1)-(C0+D1-E2)))

Measured memory_bytes: 13380
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        string s = sc.Next();
        string t = sc.Next();
        int cnt = 0;
        for (int i = 0; i < 3; i++)
        {
            if (s[i] == t[i]) cnt++;
        }

        Console.WriteLine(cnt);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 13140
num = input().split()
total = 0
for i in range(1,int(num[0])+1):
    count = 0
    i_num = str(i)
    for j in range(len(i_num)):
        count += int(i_num[j])
    if count >= int(num[1]) and count <= int(num[2]):
        total += i
print(total)

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <vector>

#define FOR(i, a, b) for (int i = a; i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define fst first
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define INIT                                                                   \
    cin.tie(0);                                                                \
    ios::sync_with_stdio(false)

using namespace std;

template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}

template <class T> void print(T &x) { cout << x << '\n'; }

int ceil(int a, int b) { return (a + b - 1) / b; }

signed main() {
    INIT;
    auto s = in<string>();
    int k = in();

    int n = s.length();
    vector<string> substr;
    map<string, int> memo;
    REP(i, n) {
        REP(j, k) {
            if (i + j == n) {
                break;
            }
            string ss = s.substr(i, j + 1);
            if (!memo.count(ss)) {
                memo[ss] = 1;
                substr.pb(ss);
            }
        }
    }
    sort(ALL(substr));
    print(substr[k - 1]);
}

Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define spe pair<string,int>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
//UnionFind

int main(){
    
    int n,m;
    int ans=0;
    vector<vector<int>> mame(10);
    int p[10];
    
    cin >> n>>m;
    
    rep(i,m){
        int k;cin >> k;
        rep(j,k){
            int a;
            cin >> a;
            mame[i].push_back(a-1);
        }
    }
    
    rep(i,m){
        cin >>p[i];
    }
    
    rep(i,1<<n){
        int onoff[10]={0};
        
        rep(j,n){
           if(i>>j&1)onoff[j]=1;
        }
        
        rep(j,m){
            int cnt=0;
            rep(k,mame[j].size()){
                cnt+=onoff[mame[j][k]];
            }
            if(cnt%2!=p[j])break;
            if(j==m-1)ans++;
        }
    }
    
    cout << ans<<endl;
    
    return 0;
}


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

int main(void)
{
	char str[81];
	int i;
	int diff;
	
	while (gets(str) != NULL){
		for (diff = 0; diff < 26; diff++){
			for (i = 0; str[i] != 0; i++){
				if ('a' <= str[i] && str[i] <= 'z'){
					str[i] -= 'a';
					str[i] = (str[i] + 1) % 26;
					str[i] += 'a';
				}
			}
			for (i = 0; str[i] != 0; i++){
				if (strncmp(&str[i], "this", 4) == 0){
					puts(str);
					diff = 26;
					break;
				}
				else if (strncmp(&str[i], "that", 4) == 0){
					puts(str);
					diff = 26;
					break;
				}
				else if (strncmp(&str[i], "the", 3) == 0){
					puts(str);
					diff = 26;
					break;
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main() {

	char c;
	cin >> c;
	c = c + 1;

	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int gcd(int a,int b){
	 return (a%b==0)?b:gcd(b,a%b);
	
} 

int main(){
	int n,x,i,ans,m;
	scanf("%d %d\n",&n,&x);
	for(i=1;i<=n;i++){
		scanf("%d",&m);
		a[i]=abs(m-x);
	}
	if(n==1){cout<<a[1];return 0;}
	ans=gcd(a[1],a[2]);
	for(i=3;i<=n;i++)
	  ans=gcd(ans,a[i]);
	cout<<ans;
	return 0;
}

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

int main() {
	string s;
	cin >> s;
	
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			for (int j = s.size() - 1; j > i; j--) {
				if (s[j] == 'Z') {
					cout << j - i + 1;
					return 0;
				}
			}
		}
	}
	cout << endl;
	return 0;
}



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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    lint h;
    cin >> h;

    lint times = 0;
    lint depth = 0;
    while (h != 1) {
        h = (lint)(h / 2);
        times += pow(2, depth);
        depth++;
    }
    times += pow(2, depth);
    cout << times << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>
#include <cctype>
#include <array>
#include <algorithm>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	int E {in}, Y {in};
	array<int, 4> a {1868, 1912, 1926, 1989};
	char s[] {"MTSH"};
	if (E)
		outl(Y + a[E - 1] - 1);
	else {
		auto r = upper_bound(begin(a), end(a), Y) - 1;
		outl(s[r - begin(a)], Y - *r + 1);
	}
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    string s;
    cin >> s;
    int n = s.size();
    int a = 0;
    int b = 0;
    rep(i, n) {
        if (s[i]=='0') a++;
        else b++;
    }

    int ans = 2*min(a, b);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pr;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define Debug printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define debug(x) cerr<<#x<<'='<<x<<endl
namespace mine
{
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;


    void main()
    {
        int y=qread();
        int x=ceil(y/1.08);
        if(1.08*x-y<1) write(x);
        else puts(":(");
    }
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

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

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

    solve();

    return 0;
}


Measured memory_bytes: 3640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
using namespace std;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
int main() {
	bitset<3>b;
	cin >> b;
	cout << b.count() << endl;
	return 0;
}

Measured memory_bytes: 256
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    string s;
    std::cin >> s;
    ll n = s.size();
    ll k;
    std::cin >> k;
    vector<vector<vector<ll>>> dp(n+5,vector<vector<ll>>(k+5,vector<ll>(2,0)));
    dp[0][0][1] = 1;
    
    for (int i = 0; i < n; i++) {
        ll x = s[i]-'0';
        for (int j = 0; j <= k; j++) {
            if(x==0){
                if(j-1>=0)dp[i+1][j][1] = dp[i][j][1];
            }else{
                if(j-1>=0)dp[i+1][j][1] = dp[i][j-1][1];
                if(j-1>=0)dp[i+1][j][0] += dp[i][j-1][1]*(x-1);
                dp[i+1][j][0] += dp[i][j][1];
            }
            if(j-1>=0)dp[i+1][j][0] += dp[i][j-1][0]*9;
            dp[i+1][j][0] += dp[i][j][0];
        }
    }

    std::cout << dp[n][k][0]+dp[n][k][1] << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
char vis[100][100];
int n,m;
int dx[8]={-1,-1,-1, 0,0, 1,1,1}; 
int dy[8]={-1, 0, 1,-1,1,-1,0,1};
void change()
{	for(int i=0;i<n;i++){

		for(int j=0;j<m;j++){
			
			int count=0;
				for(int k=0;k<8;k++)
				{
					int x=i,y=j;
					x+=dx[k];
					y+=dy[k];	
					if(x>=0&&x<n&&y>=0&&y<m)
					{ if(vis[x][y]=='#') count++;
					}		
				}
				if(vis[i][j]!='#') vis[i][j]=count+'0';
			}
		}
}
int main()
{ 	while(scanf("%d%d",&n,&m)==2)
	{ 	
		for(int i=0;i<n;i++) scanf("%s",vis[i]);
		change();
		for(int i=0;i<n;i++) cout<<vis[i]<<endl;
	}
}

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

ll odd(ll x){ return (x+1)/2 % 2;}
ll cal(ll x){
    if(x%2==1) return odd(x);
    else return odd(x+1) ^ (x+1);
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll ans = cal(b) ^ cal(a-1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq


class SSST:
    """Given weighted graph, find minimum spanning tree.

    >>> st = SSST([[(2, 3), (3, 1), (1, 2)], \
                   [(0, 2), (3, 4)], \
                   [(0, 3), (3, 1), (4, 1)], \
                   [(2, 1), (0, 1), (1, 4), (4, 3)], \
                   [(2, 1), (3, 3)]])
    >>> [st.weight(n) for n in range(5)]
    [0, 2, 2, 1, 3]
    """
    def __init__(self, graph):
        self.size = len(graph)
        self.tree = []
        self.weights = [0] * self.size
        self._search(graph)

    def weight(self, n):
        return self.weights[n]

    def _search(self, graph):
        visited = [0]

        while len(visited) < self.size:
            h = []
            for node in visited:
                for i, w in graph[node]:
                    if i not in visited:
                        heapq.heappush(h, (w+self.weights[node], node, i))

            weight, src, dst = heapq.heappop(h)
            visited.append(dst)
            self.weights[dst] = weight
            self.tree.append((src, dst))


def run():
    n = int(input())

    nodes = [None] * n
    for _ in range(n):
        id_, deg, *edges = [int(i) for i in input().split()]
        nodes[id_] = []
        for _ in range(deg):
            tgt, wgt, *edges = edges
            nodes[id_].append((tgt, wgt))

    st = SSST(nodes)
    for node in range(n):
        print('{} {}'.format(node, st.weight(node)))


if __name__ == '__main__':
    run()



Measured memory_bytes: 6196
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
using namespace std;

// const int mod = 1e9 + 7;
// inline int Add(int x) { return x >= mod ? x - mod : x; }
// inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
// inline int Sub(int x) { return x < 0 ? x + mod : x; }
// inline void Sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
// inline int Mul(int x, int y) { return (int)((li)x * y % mod); }

// int Pow(int x, int y) {
//   int z = 1;
//   for (; y; y >>= 1) {
//     if (y & 1) z = Mul(z, x);
//     x = Mul(x, x);
//   }
//   return z;
// }

// ----------------------------------------

typedef long long li;
const int maxn = 5000;
const li inf = 1e18;
int n, A, B;
int p[maxn];
li dp[maxn + 1], dp2[maxn + 1];

void Min(li &a, li b) {
  if (b < a) a = b;
}

int main(void) {
  scanf("%d%d%d", &n, &A, &B);
  swap(A, B);
  for (int i = 0; i < n; ++i) {
    scanf("%d", p + i), --p[i];
  }
  FILL(dp, n + 1, 0);

  for (int i = 0; i < n; ++i) {
    FILL(dp2, n + 1, 0x3f);
    for (int j = 0; j <= n; ++j) {
      if (j < n) Min(dp[j + 1], dp[j]);
      if (j == p[i]) {
        Min(dp2[j + 1], dp[j]);
      } else if (j < p[i]) {
        Min(dp2[j], dp[j] + B);
      } else {
        Min(dp2[j], dp[j] + A);
      }
    }
    COPY(dp2, n + 1, dp);
    // for (int j = 0; j <= n; ++j) {
    //   printf("dp[%d][%d] = %lld\n", i + 1, j, dp[j]);
    // }
  }
  for (int j = 0; j < n; ++j) {
    Min(dp[j + 1], dp[j]);
  }

  li ans = dp[n];
  printf("%lld\n", ans);
  return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  for(int t=0;t<n;t++){
    int h,w;
    cin >> h >> w;
    vector<string> f(h);
    for(int i=0;i<h;i++) cin >> f[i];
    vector<bool> use(26,false);
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(f[i][j]!='.') use[f[i][j]-'A']=true;
      }
    }
    int count=0;
    for(int i=0;i<26;i++) if(use[i]) count++;
    vector<char> alpha(count);
    int now=0;
    for(int i=0;i<26;i++) if(use[i]) alpha[now]='A'+i,now++;
    for(int i=0;i<count;i++){
      for(int j=0;j<count;j++){
        int maxx=-1,maxy=-1,miny=h,minx=w;
        for(int y=0;y<h;y++){
          for(int x=0;x<w;x++){
            if(f[y][x]==alpha[j]){
              maxx=max(maxx,x);
              maxy=max(maxy,y);
              minx=min(minx,x);
              miny=min(miny,y);
            }
          }
        }
        for(int y=miny;y<=maxy;y++){
          for(int x=minx;x<=maxx;x++){
            if(f[y][x]!=alpha[j]&&f[y][x]!='?') goto next;
          }
        }
        for(int y=miny;y<=maxy;y++){
          for(int x=minx;x<=maxx;x++){
            f[y][x]='?';
          }
        }
        next:
        continue;
      }
      // for(int i=0;i<h;i++){
      //   cout << f[i] << endl;
      // }
    }
    bool okflag=true;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(f[i][j]!='.'&&f[i][j]!='?') okflag=false;
      }
    }
    if(okflag) cout << "SAFE" << endl;
    else cout << "SUSPICIOUS" << endl;
  }

  return 0;
}



Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void ABC164B()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	while (A > 0 && C > 0)
	{
		C -= B;
		if (C <= 0)
		{
			cout << "Yes" << endl;
			return;
		}
		A -= D;
		if (A <= 0)
		{
			cout << "No" << endl;
			return;
		}
	}
}

int main()
{
	ABC164B();
	return 0;
}

Measured memory_bytes: 3564
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
from itertools import combinations
LC = list(combinations(L, 3))
for l in LC:
	if l[2] < l[0] + l[1]:
		s = set(l)
		if len(s) == 3:
			ans += 1
print(ans)



Measured memory_bytes: 20488
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<int> a(11);
	for(int i=0;i<k;i++)
	{
		int x;
		cin >> x;
		a[x]=1;
	}
	int c=n;
	while(true)
	{
		c=n; 
		int flag=0;
		while(c)
		{
			int d=c%10;
			if(a[d])
			{
				flag=1; break;
			}
			c/=10;
		}
		if(!flag)
		{
			cout << n; return 0;
		}
		n++;
	}
	cout << n;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
vector<int> svec[26], tvec[26];

int main(int argc, char const* argv[])
{
  string s, t;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    svec[s[i] - 'a'].pb(i);
  }
  for(int i = 0; i < t.size(); i++){
    tvec[t[i] - 'a'].pb(i);
  }
  bool flag = true;
  int tz = 0;
  for(int i = 0; i < 26; i++){
    if(tvec[i].size() == 0)tz++;
  }
  int sz = 0;
  for(int i = 0; i < 26; i++){
    if(svec[i].size() == 0){
      sz++;
      continue;
    }
    int index = int(t[svec[i][0]] - 'a');
    if(svec[i].size() != tvec[index].size()){
      flag = false;
      continue;
    }
    for(int j = 0; j < svec[i].size(); j++){
      if(svec[i][j] != tvec[index][j]){
        flag = false;
        break;
      }
    }
  }
  if(sz == tz && flag)cout << "Yes" << endl;
  else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 2824
#include <stdio.h>

int main(void)
{
	int input[100][2] = {0};
	int i, n, zoro, max_zoro;
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d %d", &input[i][0], &input[i][1]);
	}
	
	max_zoro = zoro = 0;
	for (i = 0; i < n; i++) {
		if (input[i][0] == input[i][1]) {
			zoro++;
		} else {
			zoro = 0;
		}
		if (zoro > max_zoro) {
			max_zoro = zoro;
		}
	}
	if (max_zoro >= 3) {
		printf("Yes");
    } else {
		printf("No");
	}

	return 0;
}


Measured memory_bytes: 1732