akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int s = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int mod = 998244353;
		long[][] dp = new long[n + 1][s + 1];
		dp[0][0] = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= s; j++) {
				dp[i + 1][j] += dp[i][j] * 2;
				if (j + a[i] <= s) {
					dp[i + 1][j + a[i]] += dp[i][j];
				}
			}
			for (int j = 0; j <= s; j++) {
				dp[i + 1][j] %= mod;
			}
		}
//		for (int i = 0; i <= n; i++) {
//			for (int j = 0; j <= s; j++) {
//				System.out.print(dp[i][j] + "\t");
//			}
//			System.out.println();
//		}
		System.out.println(dp[n][s]);
	}
}


Measured memory_bytes: 104624
#include<stdio.h>

int main(){
	int a[29],b[31],c;
	for(c=1;c<=30;c++){
		b[c]=0;
	}
	for(c=0;c<=27;c++){
		scanf("%d",&a[c]);
		b[a[c]]=1;
	}
	for(c=1;c<=30;c++){
		if(b[c]==0)printf("%d\n",c);
	}
	
	return 0;
} 

Measured memory_bytes: 0
def solve():
    import sys
    input = sys.stdin.readline

    class FenwickTree:
        def __init__(self, size):
            self.size = size
            self.array = [0]*size
    
        def add(self, index, value):
            while index < self.size:
                self.array[index] += value
                index += index&(-index)
    
        def sum(self, index):
            answer = 0
            while index > 0:
                answer += self.array[index]
                index -= index&(-index)
            return answer
    
        def rangesum(self, start, end):
            return self.sum(end)-self.sum(start-1)


    N, Q = map(int, input().split())
    *c, = map(int, input().split())
    tree2 = FenwickTree(N+1)
    m = [tuple(map(int, input().split())) for _ in range(Q)]
    idxs = sorted(tuple(range(Q)), key=lambda i: m[i][1])

    right = 0
    pos = [-1] * (N+1)
    ans = [-1] * (Q)

    for idx in idxs:
        l, r = m[idx]
        for i in range(right, r):
            x = pos[c[i]]
            if x != -1:
                tree2.add(x, -1)
            pos[c[i]] = i+1
            tree2.add(i+1, 1)
        ans[idx] = tree2.rangesum(l, r)
        right = r
    for i in ans:
        print(i)


solve()


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

int main(){
  
  int a,b,c;
  cin >> a >> b >> c;
  
  if( a <= c && c <= b ){
    
    cout << "Yes" << endl;
    
  }
  
  else{
    
    cout << "No" << endl;
    
  }
  
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define fi first
#define se second
#define pii pair<int,int>

const int maxn=2e5+10,MAX=1e9+maxn+1;
int n,a[maxn];
int it[maxn];
map<int,int> f;
int ret;
main()
{
    cin>>n;
    forinc(i,1,n) cin>>a[i];
    forinc(i,1,n){
        ret+=f[a[i]-i];
        f[-i-a[i]]++;
    }
    cout<<ret;
}


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

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    if(a==0) cout << "1" << "\n";
    if(b==0) cout << "2" << "\n";
    if(c==0) cout << "3" << "\n";
    if(d==0) cout << "4" << "\n";
    if(e==0) cout << "5" << "\n";

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
#include <unordered_map>
#include <sstream>
#include <istream>
#include <iterator>
#include <numeric>
#include <tuple>
#include <cassert>
#include <bitset>
using namespace std;

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

	int cnt[2] = {};
	for (char c : s)
		cnt[c == '0']++;

	cout << 2 * min(cnt[0], cnt[1]);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int k = 0;
  for (int &e : A) {
    cin >> e;
    k = k^e;
  }
  
  for (int i = 0; i < N; i++) {
    int j = k^A[i];
    cout << j;
    if (i < N-1) cout << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4048
#include <stdio.h>
 
int main(void) {
    int h, w;
    int i, j;
     
    while(1) {
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0) {
            break;
        }
         
        for(i = 0; i < h; i++) {
            for(j = 0; j < w; j++) {
                if((i + j) % 2 == 0) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
             
            printf("\n");
        }
         
        printf("\n");
    }
     
    return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int a, b, c;
    cin >> a >> b >> c;
    bool flg = false;
    rep(i, b - 1)
    {
        if ((i + 1) * a % b == c)
        {
            flg = true;
            break;
        }
    }
    cout << (flg ? "YES" : "NO");
    ed;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,C,ans;
  cin >> N >> K;
  C=ceil(log2(K));
  ans =pow(2,C-N>0?N:C);
  ans += (N-C)*K>0?(N-C)*K:0;
  cout << ans <<endl;
}

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

struct data{
    int a, b, c;
};


int n, m;
vector<int> v;
vector<data> dv;

bool solve(){
    vector<int> va[11][11];
    bool dp[110][110][11];


    memset(dp,0,sizeof(dp));
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<n;j++){
    //         for(int k=0;k<m;k++){
    //             dp[i][j][k] = false;
    //         }
    //     }
    // }

    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(dv[j].a == v[i]) {
                dp[i][i][j] = true;
            }
        }
    }

    for(int i=0;i<m;i++){
        va[dv[i].b][dv[i].c].push_back(i);
    }

    for(int kk=1;kk<n;kk++){
        for(int i=0;i<n-1;i++){
            int k = i + kk;
            if(i + kk >= n) break;
            for(int j=i;j<i+kk;j++){
                for(int g=0;g<m;g++){
                    for(int h=0;h<m;h++){
                        if(dp[i][j][g] && dp[j+1][k][h]){
                            for(int ii=0;ii<va[g][h].size();ii++){
                                dp[i][k][va[g][h][ii]] = true;
                            }
                        }
                    }
                }
            }
        }
    }

    return dp[0][n-1][0];
}

int main(){
    int a, b, c;
    while(cin >> n){
        v.clear();
        dv.clear();
        for(int i=0;i<n;i++){
            cin >> a;
            v.push_back(a);
        }
        cin >> m;
        for(int i=0;i<m;i++){
            cin >> a >> b >> c;
            b--; c--;
            dv.push_back((data){a, b, c});
        }
        cout << (solve() ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1348
r, g, b, n = map(int, input().split())
count=0
for i in range(0,(int)(n/r)+1):
    for j in range(0, (int)((n-i*r)/g)+1):
        v = n-i*r-j*g
        if v%b == 0 and v>=0:
            count+=1

print(count)

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

int main(){
  int N,K;cin>>N>>K;
  map<int,int>kind;
  for(int i=0;i<N;i++){
    int a; cin>>a;
    kind[a]++;
  }
  
  int n=kind.size()-K;
  
  long long res=0;
  
  vector<int>x(0);
  for(auto p:kind){
    x.push_back(p.second);
  }
  sort(x.begin(),x.end());
  for(int i=0;i<n;i++){
    res+=x.at(i);
  }
  
  cout<<res<<endl;
}

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

int main(){
  ll n,k,q;
  cin>>n>>k>>q;
  vector<ll>a(n,k);
  ll ctr=0;
  while(ctr!=q){
    ll x;
    cin>>x;
    a[x-1]++;
    // for(int i=0;i<n;i++){
    //   cout<<a[i]<<' '; 
    // }
    // cout<<endl;
    ctr++;
  }
  for(ll i=0;i<n;i++){
    // cout<<a[i]<<' '<<a[i]-q<<endl;
    if((a[i]-q)>0)
      cout<<"Yes\n";
    else
      cout<<"No\n";
  }
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<math.h>
main()
{
    long long int a,b,c,d,e,f;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    while(1)
    {
        c=c-b;
        if(c<=0)
        {
            printf("Yes");
            break;
        }
        a=a-d;
        if(a<=0)
        {
            printf("No");
            break;
        }
    }
  
 
}

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

using namespace std;

typedef long long ll;

int main(){
	int q;
	cin >> q;
	ll a[2];
	for(int i = 0; i < q; i++){
		cin >> a[0] >> a[1];
		sort(a, a+2);
		if(a[0]==a[1])cout << (a[0]-1)*2 << endl;
		else if(a[0]+1==a[1])cout << (a[0]-1)*2 << endl;
		else{
			ll c = pow(a[0]*a[1], 0.5);
			if(c*c == a[0]*a[1])c--;
			if(c*(c+1) >= a[0]*a[1])cout << 2*c-2 << endl;
			else cout << 2*c-1 << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, A, B;
    
    cin >> N >> A >> B;
    
    int trainFare = N * A;
    int taxiFare = B;
    
    if(trainFare <= taxiFare){
        cout << trainFare << endl;
    }
    else{
        cout << taxiFare << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {{typeid(int), "%d"},
                                                      {typeid(ll), "%lld"},
                                                      {typeid(double), "%lf"},
                                                      {typeid(char), "%c"}};

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

ll dp[51][51][3000];

int main(int argc, char *argv[]) {
  // INFILE();
	int n, a;
	ll total = 0;
	cin >> n >> a;

	vector<ll> v(n);
	scan(v);
	dp[0][0][0] = 1;

	REPC(i, n) REPC(j, n) REPC(k, 3000) {
		auto val = v[i];
		if (dp[i][j][k] == 0) {
			continue;
		}

		dp[i + 1][j + 1][k + val] += dp[i][j][k];
		dp[i + 1][j][k] += dp[i][j][k];
	}

	ll ans = 0;
	REP(i, 1, n + 1) {
		ans += dp[n][i][i * a];
	}

	cout << ans << "\n";
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  auto tFormat = scanType[typeid(T)];
  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 58112
#include<iostream>
#include<vector>
#include<cstdio>

using namespace std;

int main(){
  while(1){
    int n;
    char line[100];
    cin>>n;
    if(n==0)return 0;
    int list[11][11];
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
	list[i][j]=0;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin>>list[i][j];
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	list[i][n]+=list[i][j];
	list[n][i]+=list[j][i];
      }
    }
    for(int i=0;i<n;i++){
      list[n][n]+=list[n][i];
    }
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
	printf("%5d",list[i][j]);
      }
      printf("\n");
    }
  }
}

Measured memory_bytes: 0
#include<stdio.h>
#define MAX 100000
#define NIL -1

struct Node { int parent,left,right; };

struct Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL)return;
  D[u]=d;
  setDepth(T[u].left,d+1);
  setDepth(T[u].right,d+1);
}

int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].left!=NIL)
    h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL)
    h2=setHeight(T[u].right)+1;
  return H[u]=(h1>h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].parent==NIL)return NIL;
  if(T[T[u].parent].left!=u && T[T[u].parent].left!=NIL)
    return T[T[u].parent].left;
  if(T[T[u].parent].right!=u && T[T[u].parent].right!=NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].left != NIL)deg++;
  if(T[u].right != NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].parent == NIL){
    printf("root\n");
  }else if(T[u].left == NIL && T[u].right == NIL){
      printf("leaf\n");
    }else{
      printf("internal node\n");
  }
}  

int main(){
  int v,l,r,i,j,k,root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)T[i].parent=NIL;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL)T[l].parent=v;
    if(r != NIL)T[r].parent=v;
  }

  for(i=0;i<n;i++)if(T[i].parent==NIL)root=i;

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++)print(i);

  return 0;
}

Measured memory_bytes: 624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int C=sc.nextInt();
		int[][] iwakan=new int[C][C];
		for(int i=0; i<C; i++) {
			for(int j=0; j<C; j++) {
				iwakan[i][j]=sc.nextInt();
			}
		}
		int[] iwa_min=new int[C];
		for(int i=0; i<C; i++) {
			iwa_min[i]=Integer.MAX_VALUE;
			for(int j=0; j<C; j++) {
				if(i!=j) {
					iwa_min[i]=Math.min(iwa_min[i], iwakan[i][j]);
				}
			}
			//pl(i+" "+iwa_min[i]);
		}
		int[][] color=new int[N][N];
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				color[i][j]=sc.nextInt()-1;
			}
		}
		int[] mod0_color=new int[C];
		int[] mod1_color=new int[C];
		int[] mod2_color=new int[C];
		for(int i=0; i<C; i++) {
			mod0_color[i]=0;
			mod1_color[i]=0;
			mod2_color[i]=0;
		}
		for(int i=0; i<N; i++) {
			for(int j=0; j<N; j++) {
				if((i+j)%3==0) {
					mod0_color[color[i][j]]++;
				}
				else if((i+j)%3==1) {
					mod1_color[color[i][j]]++;
				}
				else if((i+j)%3==2) {
					mod2_color[color[i][j]]++;
				}
			}
		}
		//mod 0 基準
		long sum_iwa=Long.MAX_VALUE;
		long tmp_iwa=0;
/*		for(int i=0; i<C; i++) {		//いま見ている色
			tmp_iwa=0;
			for(int j=0; j<C; j++) {
				if(i!=j) {
					tmp_iwa+=mod0_color[j]*iwakan[j][i];
					pl(mod0_color[j]*iwakan[j][i]+" i!=j");
				}
				else if(i==j) {
					tmp_iwa+=(mod1_color[j]+mod2_color[j])*iwa_min[i];
					pl((mod1_color[j]+mod2_color[j])*iwa_min[i]+" i==j");
				}
			}
			pl("sum_iwa"+tmp_iwa);
			sum_iwa=Math.min(sum_iwa, tmp_iwa);
		}*/

		for(int i=0; i<C; i++) {		//mod 0の色
			for(int j=0; j<C; j++) {	//mod 1の色
				for(int k=0; k<C; k++) {//mod 2の色
					tmp_iwa=0;
					if(i!=j && j!=k && k!=i) {
						for(int l=0; l<C; l++) {
							if(i!=l) {
								tmp_iwa+=mod0_color[l]*iwakan[l][i];
							}
						}
						for(int l=0; l<C; l++) {
							if(j!=l) {
								tmp_iwa+=mod1_color[l]*iwakan[l][j];
							}
						}
						for(int l=0; l<C; l++) {
							if(k!=l) {
								tmp_iwa+=mod2_color[l]*iwakan[l][k];
							}
						}
						sum_iwa=Math.min(tmp_iwa, sum_iwa);
					}
				}
			}
		}
		pl(sum_iwa);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 39716
import java.util.Scanner;

public class Main {

    int current = 0;
    int[] stack = new int[101];

    public void go() {

        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] strs = line.split(" ");
        for (String str : strs) {
            char ch = str.charAt(0);
            if ('0' <= ch && ch <= '9') {
                this.stack[this.current] = Integer.parseInt(str);
                this.current++;
            } else {
                switch (ch) {
                case '+':
                    this.stack[current - 2] += this.stack[current - 1];
                    this.stack[current] = 0;
                    this.current--;
                    break;
                case '-':
                    this.stack[current - 2] -= this.stack[current - 1];
                    this.stack[current] = 0;
                    this.current--;
                    break;
                case '*':
                    this.stack[current - 2] *= this.stack[current - 1];
                    this.stack[current] = 0;
                    this.current--;
                    break;
                }
            }
        }
        sc.close();
        System.out.println(this.stack[current - 1]);
    }

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


Measured memory_bytes: 26224
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <map>
#include <algorithm>

using namespace std;

#define FAR (1<<22)
#define N 100

static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;


int n, color[N], d[N], p[N];
int m[N][N];

void prim(){
	for (int i = 0; i < n; ++i){
		color[i] = WHITE;
		d[i] = FAR;
		p[i] = -1;
	}

	d[0] = 0;
	int dist = FAR;

	while (1)
	{
		int u = -1;
		dist = FAR;
		for (int i = 0; i < n; ++i) {
			if (color[i] != BLACK && d[i] < dist){
				dist = d[i];
				u = i;
			}
		}

		if (-1 == u) break;
		color[u] = BLACK;

		for (int v = 0; v < n; ++v){
			if (color[v] != BLACK && (d[u] + m[u][v] < d[v])){
				d[v] = d[u] + m[u][v];
				p[v] = u;
				color[v] = GRAY;
			}
		}
	}
	for (int i = 0; i < n; ++i) cout << i << " " << d[i] << endl;
}

int main(){
	cin >> n;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j) m[i][j] = FAR;
	}

	for (int i = 0; i < n; ++i) {
		int u, d; cin >> u >> d;
		for (int j = 0; j < d; ++j) {
			int v, c; cin >> v >> c;
			m[u][v] = c;
		}
	}
 
	prim();

	return 0;
}

Measured memory_bytes: 3120
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, A; cin >> N >> A;
    int cnt = N / 500;

    N -= 500 * cnt;
    cout << (A < N ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e6 + 5;
 
struct data
{
	int clos, op, bal;
};
 
int n;
string s[N];
int bal[N];
struct data a[N];
 
void work(int idx, string &s)
{
	stack<char> st;
	for(auto &it:s)
	{
		if(it == '(')
			st.push(it);
		else
		{
			if(st.size() && st.top() == '(')
				st.pop();
			else
				st.push(')');
		}
	}
	map<char, int> m;
	while(st.size())
	{
		m[st.top()]++;
		st.pop();
	}
	a[idx].clos = m[')'];
	a[idx].op = m['('];
	a[idx].bal = m['('] - m[')'];
}
 
bool comp(struct data &a, struct data &b)
{
	if(a.clos != b.clos)
		return a.clos < b.clos;
	return a.bal > b.bal;
}
 
int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> s[i];
		work(i, s[i]);
	}
	sort(a + 1, a + n + 1, comp);
	int have = 0;
	priority_queue<pair<int, pair<int, int> > > pq;
	int i = 1, taken = 0;
	while(taken < n)
	{
		while(i <= n)
		{
			if(a[i].clos <= have)
			{
				pq.push({a[i].op, {a[i].bal, a[i].clos}});
				i++;
			}
			else
				break;
		}
		if(pq.size())
		{
			pair<int, pair<int, int> > p = pq.top();
			pq.pop();
			taken++;
			if(p.second.second > have)
			{
				cout << "No";
				return 0;
			}
			have += p.second.first;
		}
		else
		{
			cout << "No";
			return 0;
		}
	}
	if(have != 0)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}


Measured memory_bytes: 82448
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

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

func main() {
	sc.Split(bufio.ScanWords)
	
	s := scanText()

	if s[0] == s[1] || s[1] == s[2] || s[2] == s[3] {
		fmt.Println("Bad")
	} else {
		fmt.Println("Good")
	}
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}

int main(){

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    if(a + b < 2*c){
        cout << a*x + b*y << endl;
    }
    else{
        ll t1, t2;
        if(x > y){
            t1 = c * x * 2;
            t2 = c * y * 2 + a * (x - y);
        }
        else{
            t1 = c * y * 2;
            t2 = c * x * 2 + b * (y - x);
        }
        cout << min(t1, t2) << endl;
    }
    return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
using PP=pair<P,P>;
using PPP=pair<PP,ll>;
static const ll INF=1000000000000000;
struct edge{ ll to,cost;};
ll V,E;
ll d[500005];
vector<vector<edge>>G(500005);
void dijkstra(ll s){
fill(d,d+V,INF);d[s]=0;
  priority_queue<P,vector<P>,greater<P>>que;que.push(P(0,s));
  while(!que.empty()){
  P p=que.top();que.pop();
    ll v=p.second;
    if(d[v]<p.first)
      continue;
    for(auto e:G[v]){
    if(d[v]+e.cost<d[e.to]){
    d[e.to]=d[v]+e.cost;
      que.push(P(d[e.to],e.to));
     }
     }
  }
}
ll N,M;
int main(){
 cin>>N>>M;
  if(M==0)
    cout<<-1<<endl;
  else{
  set<P>S;vector<PPP>A;
  for(ll i=0;i<M;i++){
  ll p,q,c;cin>>p>>q>>c;p--;q--;
    S.insert(P(p,c));
    S.insert(P(q,c));
    S.insert(P(p,0));
    S.insert(P(q,0));
  PPP X=PPP(PP(P(p,c),P(p,0)),1);
    PPP Y=PPP(PP(P(p,c),P(q,c)),0);
    PPP Z=PPP(PP(P(q,c),P(q,0)),1);
  A.push_back(X);
    A.push_back(Y);
    A.push_back(Z);
  }map<P,ll>m;
  ll I=0;
  V=S.size();
  for(auto x:S){
  m[x]=I;I++;
  }if(!m.count(P(N-1,0)) ||!m.count(P(0,0)))
    cout<<-1<<endl;
    else{
    ll t=m.at(P(N-1,0));
  E=A.size();
  for(ll i=0;i<E;i++){
  PPP ppp=A[i];
    PP pp=A[i].first;
    P p1=A[i].first.first;
    P p2=A[i].first.second;
    ll c=A[i].second;
    ll p=m.at(p1);ll q=m.at(p2);
    edge e;e.to=q;e.cost=c;
    edge e1;e1.to=p;e1.cost=c;
    G[p].push_back(e);
    G[q].push_back(e1);
  }dijkstra(0);
  if(d[t]<INF)
    cout<<d[t]/2<<endl;
    else
      cout<<-1<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 137060
from collections import deque
    
N,M = list(map(int,input().split()))

node_list = [[] for i in range(N)]

for i in range(M):
    x,y,z=list(map(int,input().split()))
    node_list[x-1].append(y-1)
    node_list[y-1].append(x-1)

checked_list = [-1 for i in range(N)]

def BFS(start,color,checked_list,node_list):
    Q=deque([start])
    checked_list[start]=color
    while len(Q)>0:
        v1 = Q.pop()
        for v2 in node_list[v1]:
            if checked_list[v2]==-1:
                checked_list[v2]=color
                Q.appendleft(v2)


count = 0
for i in range(N):
    if checked_list[i]==-1:
        BFS(i,count,checked_list,node_list)
        count+=1
        
print(count)

Measured memory_bytes: 27836
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 100100;
const int MAX_C = 31;
int N,C;
vector<tuple<int, int, int>> cs;
priority_queue<int, vector<int>, greater<int>> last[100];
int main() {

  cin >> N >> C;
  for (int i = 0; i < N; i++){
    int s,t,c;
    cin >> s >> t >> c;
    c--;
    cs.emplace_back(mt(s, t, c));
  }
  sort(cs.begin(), cs.end());
  int result = 0;
  for (int i = 0; i < cs.size(); i++){
    int s,t,c;
    tie(s, t, c) = cs[i];
    while (not last[c].empty()){
      int l = last[c].top();
      if (l <= s){
        last[c].pop();
      }
    }
    // cerr << last[c].size() << endl;
    last[c].push(t);
    int tmp = 0;
    for (int j = 0; j < C; j++){
      while (not last[j].empty()){
        if (last[j].top() < s){
          last[j].pop();
        }else{
          break;
        }
      }
      tmp += last[j].size();
    }
    result = max(result, tmp);
  }
  cout << result << endl;
  return 0;
}


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

priority_queue<int, vector<int>, less<int> >myque[1000];
int main() {
	int r,T;
	cin >>r>> T;
	while (T--)
	{
		int a, b, c;
		scanf("%d", &a);
		switch (a)
		{
		case 0:
			cin >> b >> c;
			myque[b].push(c);
			break;
		case 1:
			cin >> b;
			if (!myque[b].empty())cout << myque[b].top()<< endl;
			break;
		case 2:
			cin >> b;
			if (!myque[b].empty())myque[b].pop();
		default:
			break;
		}
	}
 
	return 0;
}




Measured memory_bytes: 4120
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B):
    if A == 2 or B == 2:
        return 'No'
    return "Yes"


def main():
    A, B = read_int_n()
    print(slv(A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7340
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	arry := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arry[i])
	}
	min := 1000000000
	max := 0
	for i := 0; i < n; i++ {
		if arry[i] < min {
			min = arry[i]
		}
		if arry[i] > max {
			max = arry[i]
		}
	}
	fmt.Println(max - min)

}


Measured memory_bytes: 512
#include  <functional>
#include  <algorithm>
#include  <exception>
#include  <stdexcept>
#include  <streambuf>
#include  <iterator>
#include  <string.h>
#include  <stdlib.h>
#include  <typeinfo>
#include  <valarray>
#include  <iostream>
#include  <sstream>
#include  <istream>
#include  <stdio.h>
#include  <climits>
#include  <clocale>
#include  <complex>
#include  <csetjmp>
#include  <csignal>
#include  <cstdarg>
#include  <cstddef>
#include  <ctype.h>
#include  <cassert>
#include  <cstdlib>
#include  <utility>
#include  <cstring>
#include  <numeric>
#include  <ostream>
#include  <cwctype>
#include  <fstream>
#include  <iomanip>
#include  <math.h>
#include  <bitset>
#include  <cctype>
#include  <string>
#include  <vector>
#include  <limits>
#include  <locale>
#include  <memory>
#include  <cerrno>
#include  <time.h>
#include  <iosfwd>
#include  <cfloat>
#include  <cstdio>
#include  <cwchar>
#include  <cmath>
#include  <ctime>
#include  <deque>
#include  <queue>
#include  <stack>
#include  <list>
#include  <ios>
#include  <map>
#include  <set>
#include  <new>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
using namespace std;
ll a,b,c,d,n;
ll min1,min2;
ll ans;
int main()
{
    cin>>a>>b>>c>>d>>n;
    a*=4;b*=2;
    min1=min(a,b);
    min1=min(min1,c);
    min2=min(min1*2,d);
    int t=n/2;
    ans=t*min2;
    if(n%2!=0)
        ans+=min1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    // char ;
    ll num[3],ans=0;
    rep(i,0,3){
        scanf("%lld",&num[i]);
    }
    sortup(num,3);
    // ll [n];
    // rep(i,0,n){
    //     scanf("%lld",&[i]);
    // }
    ans+=num[2]-num[1];
    num[0]+=num[2]-num[1];
    if( (num[2]-num[0])%2 ){
        ans+=(num[2]-num[0])/2+2;
    }else{
        ans+=(num[2]-num[0])/2;
    }
    printf("%lld\n",ans);
    return 0;
}


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

struct UnionFind{
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(data[y] < data[x]) swap(x,y);
    data[x] += data[y];
    data[y] = x;
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
};

bool in_range(int a, int b){
  return a >= 0 && a < b;
}

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};
  for(int i = 0; i < H; ++i) cin >> S[i];
  UnionFind uf(H*W);
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      for(int k = 0; k < 4; ++k){
        int i_ = i + dx[k], j_ = j + dy[k];
        if(in_range(i_,H) and in_range(j_,W) and S[i][j] != S[i_][j_]){
          uf.unite(i*W+j,i_*W+j_);
        }
      }
    }
  }
  long long ans = 0;
  map<int,pair<int,int> > M;
  for(int i = 0; i < H*W; ++i){
    if(S[i/W][i%W] == '#') ++M[uf.find(i)].first;
    else ++M[uf.find(i)].second;
  }
  for(auto e : M){
    ans += (long long)(e.second.first)*e.second.second;
  }
  cout << ans << endl;
}


Measured memory_bytes: 9728
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>

#pragma warning( disable: 4996 )

using namespace std;

typedef long long ll;

#define INF 1000000000
#define EPS 1e-10

#define MAX_N 100
#define MAX_A 10000
#define MAX_B 10000
#define MAX_C 10000

int N, A, B, C, X;
int Y[MAX_N];

vector<int> ans_list;

int main(){

	while (true){

		cin >> N >> A >> B >> C >> X;
		if (N == 0)
			break;

		int ans = 0;

		for (int i = 0; i < N; i++){
			cin >> Y[i];
		}

		for (int i = 0; i < N; i++){
			if (i != 0){
				X = (A * X + B) % C;
				ans++;
			}
			while (Y[i] != X){
				ans++;
				X = (A * X + B) % C;
				if (ans > 10000)
					break;
			}
			if (ans > 10000)
				break;
		}

		if (ans <= 10000)
			ans_list.push_back(ans);
		else
			ans_list.push_back(-1);

	}

	for (int i = 0; i < ans_list.size(); i++){
		cout << ans_list[i] << endl;
	}

	return 0;

}

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

int main() {
    long long N,K;
    cin >> N >> K;
    int L = K;
    long long count = 1;
    for(int i=0;i < N - L + 1;i++){
        count += ((2 * N - K + 1) * K / 2 - K * (K - 1) / 2 + 1)  % 1000000007;
        K++;
    }
    count %= 1000000007;
    cout << count << endl;
}

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

int main() {
  string s;
  cin >> s;
  int count1 = 0;
  rep(i, 4){
    for(int k = i + 1; k<4;k++){
      if (s.at(i) == s.at(k)) {
        count1++;
      }
    }
  }
  if (count1 == 2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    ll ans = LLONG_MAX;
    rep(i, n) rep(j, n) rep(s, n) rep(t, n) {
        ll xl = x[i];
        ll xr = x[j];
        ll yl = y[s];
        ll yr = y[t];
        if (xl >= xr || yl >= yr) continue;
        int cnt = 0;
        rep(k, n) {
            if(xl <= x[k] && x[k] <= xr && yl <= y[k] && y[k] <= yr){
                cnt++;
            }
        }
        if(cnt >= k){
            ans = min(ans, (xr - xl) * (yr - yl));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=1000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

char ans[N][N];

int main()
{
    int n=read(),m=read(),A=read(),B=read();
    int opn=0,opm=0;
    rep(i,1,n) rep(j,1,m) ans[i][j]='.';
    if (n&1)
    {
        for (int i=2;i<=m && A;i+=2)
        {   
            ans[n][i-1]='<';ans[n][i]='>';A--;
        }
        n--;opn=1;
    }
    if (m&1)
    {
        for (int i=2;i<=n && B;i+=2)
        {
            ans[i-1][m]='^';ans[i][m]='v';B--;
        }
        m--;opm=1;
    }
    if ((opn) && (opm) && ((A+B)*2==n*m) && (A&1))
    {
        ans[n-1][m-1]='<';ans[n-1][m]='>';ans[n-1][m+1]='^';
        ans[n][m-1]='^';ans[n][m+1]='v';
        ans[n+1][m-1]='v';ans[n+1][m]='<';ans[n+1][m+1]='>';
        A--;B--;
    }
    //cout << "rst " << A << " " << B << endl;
    for (int i=2;i<=n;i+=2)
    {
        for(int j=2;j<=m;j+=2)
        {
            if (A)
            {
                ans[i-1][j-1]='<';ans[i-1][j]='>';A--;
                if (A) {ans[i][j-1]='<';ans[i][j]='>';A--;}
            }
            else if (B)
            {
                ans[i-1][j-1]='^';ans[i][j-1]='v';B--;
                if (B) {ans[i-1][j]='^';ans[i][j]='v';B--;}
            }
        }
    }
    if (A+B) {puts("NO");return 0;}
    puts("YES");
    n+=opn;m+=opm;
    rep(i,1,n)
    {
        rep(j,1,m) putchar(ans[i][j]);
        puts("");
    }
    return 0;
}
            


Measured memory_bytes: 2304
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
int sum[2010][2010],SUM[2010][2010];
bool s[2010][2010];

int main(){
    int h,w;cin>>h>>w;
    rep(i,h)rep(j,w){
        char t;cin>>t;
        if(t=='.')s[i][j]=1;
        else s[i][j]=0;
        }
    rep(i,h)sum[i][0]=s[i][0];
    rep(i,h)rep(j,w){
        if(s[i][j+1]==0){sum[i][j+1]=0;continue;}
        sum[i][j+1]=sum[i][j]+s[i][j+1];
    }
    rep(i,h)for(int j=1;j<w;j++){
        if(sum[i][w-j-1]&&sum[i][w-j])sum[i][w-j-1]=sum[i][w-j];
    }
    rep(i,w)SUM[0][i]=s[0][i];
    rep(i,w)rep(j,h){
        if(s[j+1][i]==0){SUM[j+1][i]=0;continue;}
        SUM[j+1][i]=SUM[j][i]+s[j+1][i];
    }
    rep(i,w)for(int j=1;j<h;j++){
        if(SUM[h-j-1][i]&&SUM[h-j][i])SUM[h-j-1][i]=SUM[h-j][i];
    }
    ll ans=0;
    rep(i,h)rep(j,w){
        if(s[i][j])chmax(ans,sum[i][j]+SUM[i][j]-1);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 35712
#include "bits/stdc++.h"
using namespace std;


/* macro */
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


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




/* main */



signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    
    string s = raw_input();

    if(s[0] == s[2]){
        print("Yes");
    }else{
        print("No");
    }

    

    
    




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










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

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

	string S, T;
	cin >> S;
	cin >> T;

	vector<int> D(26, -1);
	vector<bool> stock(26, false);
	for (int i = 0; i < S.size(); i++) {
		if (D[S[i] - 'a'] == -1) {
			if (stock[T[i] - 'a']) {
				printf("No");
				return 0;
			} else {
				D[S[i] - 'a'] = T[i];
				stock[T[i] - 'a'] = true;
				// cout << "D[" << S[i] << "] =" << T[i] << "\n";
			}
		} else if (D[S[i] - 'a'] == T[i]) {
			continue;
		} else {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const long long MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
ll gcd(ll a,ll b){//aとbの最大公約数を返す//計算量は0(log(max(a,b))
  if(a%b==0){return b;}
  else{return gcd(b,a%b);}
}
ll lcm(ll a,ll b){//aとbの最小公倍数を返す//計算量は0(log(max(a,b))
  return a*b/gcd(a,b);
}
ll pow(ll x,ll y){//x^yを返す//計算量は0(log(y))
  ll tmp=x,res=1;
  while(y){
    if(y%2){res=res*tmp%MOD;}
    y>>=1;
    tmp=tmp*tmp%MOD;
  }
  return res;
}
ll nature(ll a){//絶対値を返す
  if(a>=0){return(a);}
  else{return(-1*a);}
}
ll prime(ll a){//素数なら1を返す//計算量は0(sqrt(a))
  if(a==2){return 1;}
  else if(a%2==0 || a==1){return 0;}
  for(ll i=3;i*i<=a;i+=2){if(a%i==0){return 0;}}
  return 1;
}
int main(){
  ll N;
  cin>>N;
  ll dp[120][120][120];
  unordered_map<ll,ll> mp;
  for(int i=1;i<=110;i++){
    for(int j=1;j<=110;j++){
      for(int k=1;k<=110;k++){
        long long a=i*i+j*j+k*k+i*j+j*k+k*i;
        if(a<=N){
          mp[a]++;
          //cout<<i<<" "<<j<<" "<<k<<" "<<a<<endl;
                }
      }
    }
  }
  for(int i=1;i<=N;i++){
    cout<<mp[i]<<endl;
  }
}

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


typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
int main(){
	int N,k,mid;
	cin>>N;
	vector<int> ss;
	for(int i=0;i<N;i++){
		cin>>k;
		ss.push_back(k);
	}
	sort(ss.begin(),ss.end());
	mid=N/2;
	cout<<ss[mid]-ss[mid-1]<<endl;
	return 0;
}

Measured memory_bytes: 892
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>
#include<bitset>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

// char to int
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

const int FLAG_NUM = 10;
// 1023 => 1111 1111
vector<int> num_to_flags(int x){
    stringstream ss;
    ss << static_cast<std::bitset<FLAG_NUM> >(x);
    string s = ss.str();
    vector<int> V(FLAG_NUM);
    FOR(i, 0, FLAG_NUM){
        V[i] = ctoi(s[i]);
    }
    return V;
}

void pV(vector<int> v){
    for(auto a : v){
        cout << a << " ";
    }
    cout << endl;
}

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

    // input
    int N;
    cin >> N;

    vector<vector<int> > F(N);
    FOR(i, 0, N){
        FOR(j, 0, 10){
            int f;
            cin >> f;
            F[i].push_back(f);
        }
    }

    vector<vector<int> > P(N);
    FOR(i, 0, N){
        FOR(j, 0, 11){
            int p;
            cin >> p;
            P[i].push_back(p);
        }
    }

    ll max_profit = -inf;
    FOR(i, 1, 1024){
        auto flags = num_to_flags(i);

        ll profit_sum = 0;
        FOR(j, 0, N){
            auto tenpo = F[j];
            int both_work = 0;
            FOR(k, 0, 10){
                if(tenpo[k]==1 && flags[k]==1){
                    both_work++;
                }
            }
            int profit = P[j][both_work];
            profit_sum += profit;
        }
        max_profit = max(max_profit, profit_sum);
    }

    p(max_profit);
    
    return 0;
}

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

#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define tr(container, it) \
      for(typeof(container.begin()) it = container.begin(); it != --container.end(); it++,container.end()++)
#define present(container, element) (container.find(element) != container.end()) 
#define cpresent(container, element) (find(all(container),element) != container.end()) 
#define se second
#define fi first
#define sz(a) int((a).size()) 
#define pb push_back 



int main()
{
	//freopen("input.txt","r",stdin);
	speed;
	
	int n;
	cin>>n;
	if(n<=999) cout<<"ABC";
	else cout<<"ABD";
    return 0;
}

Measured memory_bytes: 256