akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    int h,r;
    cin>>h>>r;
    if(h+r==0){
        cout<<0<<'\n';
    }
    if(h+r<0){
        cout<<-1<<'\n';
    }
    if(h+r>0){
        cout<<1<<'\n';
    }
}


Measured memory_bytes: 3108
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int A, B; scanf("%d%d", &A, &B);
	int a, b, c;
	a = A + B;
	b = A - B;
	c = A*B;

	printf("%d", max(max(a, b), c));

	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	switch {
	case a == b:
		fmt.Println(c)
	case b == c:
		fmt.Println(a)
	default:
		fmt.Println(b)
	}
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main()
{
    int n, l;
    scanf("%d %d", &n, &l);
    int i;
    char s[102][102];
    for (i = 0; i < n; i++)
        scanf("%s", s[i]);
    char x[102];
    int j;
    for (i = 0; i < n - 1; i++)
    {
        j = 0;
        if (strcmp(s[i], s[i + 1]) != 0)
        {
            while (s[i][j] == s[i + 1][j])
                j++;
            if (s[i][j] - s[i + 1][j] > 0)
            {
                strcpy(x, s[i]);
                strcpy(s[i], s[i + 1]);
                strcpy(s[i + 1], x);
                if (i > 0)
                    i -= 2;
            }
        }
    }
    for (i = 0; i < n; i++)
        printf("%s", s[i]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
n = int(input())

a = []
a.append(list(map(int, input().split())))
a.append(list(map(int, input().split())))

b = [[0] * n, [0] * n]

for i in range(n):
    if i == 0:
        b[0][i] = a[0][0]
        b[1][i] = a[0][0] + a[1][0]
    else:
        b[0][i] = a[0][i] + b[0][i - 1]
        b[1][i] = max(b[0][i], b[1][i - 1]) + a[1][i]

print(b[1][n - 1])


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

using namespace std;
typedef long long ll;

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

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

  int a[N+1];
  a[0] = -1;
  for(int i=1; i<N+1; i++)
    cin >> a[i];

  
  vector<int> box(N+1);
  box[0]=-1;
  for(int i=1; i<N+1; i++)
    box[i]=0;

  ll count=0;
  for(int i=N; i>0; i--)
    {
      int sum = 0;
      //n/2以上のiは倍数が自身のみ
      for(int j=1; i*j<N+1; j++)
	{
	  sum += box[i*j];
	}
      if(sum%2!=a[i])
	{
	  box[i]++;
	  count++;
	}
    }
  
  cout << count << endl;
  for(int i=1; i<N+1; i++)
    {
      if(box[i])
	cout << i  << " ";
    }
  cout << endl;
  
  
  


  return 0;
}


//cout << setprecision(13);
//next_permutation(v.begin(), v.end());



Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

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

  vector<string> x = {"maerd", "remaerd", "esare", "resare"};
  reverse(rng(s));
  //show(s);
  rep(i,s.size()) {
    //show(i);
    if (s.substr(i,5) == x[0] || s.substr(i,5) == x[2]) {
      i += 5-1;
    }
    else if (s.substr(i,6) == x[3]) {
      i += 6-1;
    }
    else if (s.substr(i,7) == x[1]) {
      i += 7-1;
    }
    else {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N = 1087;
const double inf = 1e15;
struct circ
{
    int x,y,r;
} c[N];
double d[N];
bool vis[N];
double dist(int u,int v)
{
    long long dx = c[u].x-c[v].x, dy = c[u].y-c[v].y, rr = c[u].r + c[v].r;
    long long w = dx * dx + dy * dy;
    if (w <= rr * rr)
        return 0;
    return sqrt(w) - rr;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> c[0].x >> c[0].y >> c[1].x >> c[1].y >> n;
    c[0].r = c[1].r = 0;
    n += 2;
    for (int i = 2; i < n; ++i)
        cin >> c[i].x >> c[i].y >> c[i].r;
    fill_n(d,n,inf);
    d[0] = 0;
    for (int i = 0; i < n; ++i) {
        int u = -1;
        double mn = inf;
        for (int j = 0; j < n; ++j)
            if (!vis[j] && d[j] < mn) {
                mn = d[j];
                u = j;
            }
        if (u == 1) {
            cout << fixed << setprecision(16) << d[u] << endl;
            return 0;
        }
        vis[u] = 1;
        for (int j = 0; j < n; ++j)
            if (!vis[j])
                d[j] = min(d[j], d[u] + dist(u,j));
    }
}


Measured memory_bytes: 256
// 
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


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

    int n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=k+1;i<=n;i++){
        if(a[i-k]<a[i]) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const double pi =  acosl(-1);
const long long inf = 1e18 + 5;
using namespace std;
template<typename T> void debug(string s, T x)
{
	cout << s << " = " << x << "\n";
}
template<typename T, typename... Args> void debug(string s, T x, Args... args)
{
	cout << s.substr(0, s.find(',')) << " = " << x << " | ";
	debug(s.substr(s.find(',') + 2), args...);
}
template<class T> void print_container(T &container)
{
	for (auto &t : container)
	{
		cout << t << " ";
	}
	cout << endl;
}
template<class T> void print_pair_container(T &container)
{
	for (auto &t : container)
	{
		cout << t.first << " " << t.second << endl;
	}
	cout << endl;
}
template<class T> void printArr(T &a, int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << a[i] << " ";
	}
	cout << endl;
}
typedef long long ll;
typedef pair<int, int> pii;

//Template Ends
int n;

ll power(ll a, ll n, ll m) {
	a %= m;
	ll res = 1;
	while (n > 0) {
		if (n % 2)
			res = res * a % m;
		a = a * a % m;
		n /= 2;
	}
	return res;
}

void solve()
{
	cin >> n;

	cout << ( power(10, n , mod) % mod  - (2 * power(9, n, mod) % mod) % mod +  power(8, n, mod) % mod + mod ) % mod << endl;
}

int32_t main()
{
	IOS;
#ifndef ONLINE_JUDGE
	freopen("../../input.txt", "r", stdin);
	freopen("../../output.txt", "w", stdout);
#endif

	solve();

	return 0;
}



Measured memory_bytes: 3604
fun main(args: Array<String>) {
    val text = readLine()!!
    val keyWords = listOf("dream", "dreamer", "erase", "eraser")
    var result = "NO"
    var sb = StringBuilder(text)
    while(true) {
        var changed = false
        for (keyWord in keyWords) {
            if (sb.endsWith(keyWord)) {
                sb.delete(sb.length - keyWord.length, sb.length)
                changed = true
                break
            }
        }
        if (!changed) {
            break
        }
        if (sb.isEmpty()) {
            result = "YES"
            break
        }
    }
    print(result)
}

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

typedef long long ll;

ll N;

int main() {
  cin >> N;
  double x;
  string u;
  double sum = 0.0;
  for (int i=0; i<N; i++){
    cin >> x >> u;
    if (u == "JPY"){
      sum += x;
    }else{
      sum += x*380000.0;
    }
  }
  cout << fixed << setprecision(6) << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(void) {
    int n, x;
    std::cin >> n >> x;

    int count = 1;
    int d = 0;
    int l;
    for (int i = 0; i < n; i++) {
        std::cin >> l;
        d += l;
        if (d <= x) {
            count++;
        }
    }
    std::cout << count << std::endl;

    return EXIT_SUCCESS;
}


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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int use[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<string> dp(n + 1);
  for (int i = 0; i < m; ++i) {
    cin >> a[i];
    if (use[a[i]] <= n) {
      string s = to_string(a[i]);
      if (dp[use[a[i]]].empty() || dp[use[a[i]]] < s) {
        dp[use[a[i]]] = s;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      int before = i - use[a[j]];
      if (before < 0) continue;
      if (dp[before].empty()) continue;
      string cand = dp[before] + to_string(a[j]);
      if (dp[i].size() < cand.size() || (dp[i].size() == cand.size() && dp[i] < cand)) {
        dp[i] = cand;
      }
    }
  }

  cout << dp[n] << "\n";
}


Measured memory_bytes: 32000
#include<iostream>
#include<map>
#define pf p.first
#define ps p.second
using namespace std;
typedef pair<int,int>P;
int h,w,mas[20][20],memo[20][20],ans,tmp[]={-1,0,1};
int dfs(P);
int main(){
  while(cin >> w >> h && w||h){
    ans = 0;
    for(int i=0;i<20;i++) for(int j=0;j<20;j++) memo[i][j] = -1;
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> mas[i][j];
    for(int i=0;i<w;i++) ans += dfs(P(0,i));
    cout << ans << endl;
  }
}
int dfs(P p){
  if(memo[pf][ps] != -1) return memo[pf][ps];
  if(mas[pf][ps] == 1) return 0;
  if(pf >= h - 1) return 1;
  if(mas[pf][ps] == 2) return (memo[pf][ps] = dfs(P(pf+2,ps)));
  else{
    int cnt = 0;
    for(int i=0;i<3;i++){
      int nx = pf + 1,ny = ps + tmp[i];
      if(ny>=0&&ny<w&&((mas[nx][ny]==0)||(mas[nx][ny]==2&&i==1))){
	  cnt += dfs(P(pf+1,ps+tmp[i]));
	}
    }
    return (memo[pf][ps] = cnt);
  }
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vector<P> v(n);
  rep(i, n) {
    int x; cin >> x;
    v[i] = make_pair(i, x);
  }
  sort(v.begin(), v.end(), greater<P>());

  ll ans = 0;
  vector<ll> a(n), b(n);
  rep(i, n) {
    a[i] = (v[i].second - v[i].first);
    b[i] = (-v[i].second - v[i].first);
  }
  sort(b.begin(), b.end());
  rep(i, n) {
    ans += upper_bound(b.begin(), b.end(), a[i]) - lower_bound(b.begin(), b.end(), a[i]);
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 7940
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int h, w, c;
int panel[8][8];

class node {
public:
	int panel[8][8], tmpPanel[8][8];
	int d;
	int area;
	node(int src[8][8]){
		memcpy(panel, src, sizeof(panel));
		memcpy(tmpPanel, panel, sizeof(panel));
		getArea(0, 0, panel[0][0]);
		area = 0;
		d = 0;
	}
	node(int src[8][8], int i, int _d=0){
		memcpy(panel, src, sizeof(panel));
		area = 0;
		flip(0, 0, this->panel[0][0], i);
		memcpy(tmpPanel, panel, sizeof(panel));
		getArea(0, 0, i);
		d = _d;
	}
	void flip(int x, int y, int c1, int c2) {
		this->panel[x][y] = c2;
		for (int i = 0; i < 4; i++) {
			int nextX = x + dx[i];
			int nextY = y + dy[i];
			if (0 <= nextX && nextX < w && 0 <= nextY && nextY < h && this->panel[nextX][nextY] == c1) {
				flip(nextX, nextY, c1, c2);
			}
		}
	}
	void getArea(int x, int y, int c) {
		tmpPanel[x][y] = -1;
		this->area++;
		for (int i = 0; i < 4; i++) {
			int nextX = x + dx[i];
			int nextY = y + dy[i];
			if (0 <= nextX && nextX < w && 0 <= nextY && nextY < h && this->tmpPanel[nextX][nextY] == c) {
				getArea(nextX, nextY, c);
			}
		}
	}
	bool operator < (const node& o) const {
		return this->area < o.area;
	}
};

void debug(node& n){
	cout << "Debug===========================" << endl;
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++)
			cout << n.panel[j][i] << " ";
		cout<< endl;
	}
	cout << n.area << endl;
}

int solve() {
	int maxArea = 0;
	node root(panel);
	priority_queue<node> q;
	q.push(root);
	while (!q.empty()) {
		node current = q.top();q.pop();
		//debug(current);
		if (current.panel[0][0] == c)
			maxArea = max(maxArea, current.area);
		for (int i = 1; i < 7; i++) {
			if (current.d + 1 == 6) continue;
			if (current.panel[0][0] == i) continue;
			if (current.d == 3 && i == c) continue;
			node next(current.panel, i, current.d + 1);
			q.push(next);
		}
	}
	return maxArea;
}

int main() {
	while (cin >> h >> w >> c, h || w || c) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> panel[j][i];
			}
		}
		cout << solve() << endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,k,s1=0,s2=0;
cin>>n>>k;
for(int i=1;i<=n;i++) {
int x;
cin>>x;
if(x&1) ++s1;
else ++s2;
}
if(!s1) {
if(k) puts("0");
else cout<<(1LL<<s2);
}
else cout<<(1LL<<(n-1));
return 0;
}

Measured memory_bytes: 768
N, K = list(map(int, input().split(' ')))
S = list(input())

def change():
    check = S[0]
    k = 1
    while S[k] == check:
        k += 1
    i = 0
    while S[k + i] != check:
        S[k + i] = check
        i += 1

group = 1
old = S[0]
happy_num = 0
for i in range(1, N):
    if old == S[i]:
        group += 1
        if i == N - 1:
            happy_num += group - 1
    else:
        happy_num += group - 1
        old = S[i]
        group = 1
#print(happy_num)


old = S[0]
border = 0
for i in range(1, N):
    if old != S[i]:
        border += 1
        old = S[i]
#print(border)

changed = 2 * K
if changed < border:
    print(happy_num + 2 * K)
else:
    print(N - 1)

Measured memory_bytes: 4084
import java.util.Scanner;
class Main{
     public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
    	Dice dice1 = new Dice();
    	int[] v = new int[6];
    	
    	for(int i = 0; i < 6; i++){
    		dice1.S[i] = scan.nextInt();
    		v[i] = i;
    	}
    	
    	String order = scan.next();
    	char[] c_order = new char[order.length()];
    	
    	for(int i = 0; i < order.length(); i++){
    		c_order[i] = order.charAt(i);
    		int buf;
    		switch(c_order[i]){
    			case 'N':{
    				buf = v[0];
    				v[0] = v[1];
    				v[1] = v[5];
    				v[5] = v[4];
    				v[4] = buf;
    				break;
    			}
    			case 'E':{
        			buf = v[0];
        			v[0] = v[3];
        			v[3] = v[5];
        			v[5] = v[2];
        			v[2] = buf;
        			break;
    			}
    			case 'W':{
    				buf = v[0];
        			v[0] = v[2];
        			v[2] = v[5];
        			v[5] = v[3];
        			v[3] = buf;
        			break;
    			}
    			case 'S':{
    				buf = v[0];
        			v[0] = v[4];
        			v[4] = v[5];
        			v[5] = v[1];
        			v[1] = buf;
        			break;
    			}
    		}
    	}
    	
    	
    	System.out.println(dice1.S[v[0]]);
     }
}

class Dice{
	int[] S = new int[6];
}

Measured memory_bytes: 26196
#include<bits/stdc++.h>
#define M 1<<25
using namespace std;long long a[M],b[M],c[M],x[M],n,p,q,i,s,m;main() {cin>>n>>p>>q;c[0]=p*q;for(i=0;i<n;i++){cin>>b[i];a[i]=b[i]-(q-i)*p;s+=b[i];}sort(a,a+n);m=s;for(i=0;i<n;i++){s-=a[i]-2*i*p;m=max(s,m);}cout<<m<<endl;}

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

int main(){
  while(1){
    int n; cin>>n;

    if(n==0) break;
    
    vector<double> sx(n),sy(n),sz(n);
    
    for(int i=0; i<n; i++){
      cin>>sx[i]>>sy[i]>>sz[i];
    }
    
    int m; cin>>m;
    
    vector<double> tx(m),ty(m),tz(m),kaku(m);
    
    for(int  i=0; i<m; i++){
      cin>>tx[i]>>ty[i]>>tz[i]>>kaku[i]; 
    }
    
    int count=0;
    
  set<int> s;
  
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      if(s.count(i))continue;
      
      double seki = tx[j]*sx[i] + ty[j]*sy[i]+ tz[j]*sz[i];
      
      double pLong = sqrt(sx[i]*sx[i] + sy[i]*sy[i] + sz[i] * sz[i]);
      
      double kLong = sqrt(tx[j]*tx[j] + ty[j]*ty[j] + tz[j] * tz[j]);

      double theta = acos(seki / (pLong * kLong));
      
      if(theta <=kaku[j]){
        count++;
        s.insert(i);
      }
    }
  }
  cout<<count<<endl;
  }
  
  return 0;
}



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

int main() {
    int n,k; scanf("%d %d", &n, &k);
    int bats = (1 << n);

    if (n == 1 && k == 0) {
        puts("0 0 1 1");
        return 0;
    } else if (n == 1 && k == 1) {
        puts("-1");
        return 0;
    } else if (k >= bats) {
        puts("-1");
        return 0;
    }

    for (int i=0; i<bats; i++) {
        if (i != k) {
            printf("%d ", i);
        }
    }
    printf("%d ", k);
    for (int i=bats-1; i>=0; i--) {
        if (i != k) {
            printf("%d ", i);
        }
    }
    printf("%d\n", k);
    return 0;
}

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

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

    vector<int> A(N, 0);
    for(auto&& a: A){
        cin >> a;
    }

    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i + 1; j < N; ++j)
        {
            ans = max(ans, abs(A[i] - A[j]));
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, s, e) for(int i=s; i>=e; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> void vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


const int MAXN = 100010;

class UnionFind {
    int par[MAXN];
    int rank[MAXN];

public:
    UnionFind(int n){
        rep(i, n){
            par[i] = i;
            rank[i] = 0;
        }
    }

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

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

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

    int n, m, x, y, tmp;
    vector<int> p;
    vector<pair<int, int>> ppair;
    vector<pair<int, int>> xy;
    p.push_back(0);

    cin >> n >> m;
    rep(i, n){
        cin >> tmp;
        p.push_back(tmp);
        ppair.push_back(make_pair(tmp, i+1));
    }
    rep(i, m){
        cin >> x >> y;
        xy.push_back(make_pair(x, y));
    }

    UnionFind tree(n+1);
    for(auto e : xy){
        tree.unite(e.first, e.second);
    }

    sort(all(ppair));

    ll res = 0;
    rep(i, n){
        int num = ppair[i].first;
        int ind = ppair[i].second;

        if(p[num] == num){
            res++;
        }else if(tree.same(num, p[num])){
            res++;
            //swap(p[ind], p[num]);
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3184
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
    int n;
    cin >> n;

    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            if(n==i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using ll = long long;

ll p[100002] = {0};

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

    for (ll n = 1; n < N + 1; n++) { cin >> p[n]; }

    ll cnt = 0;

    if (p[1] == 1) {
        swap(p[1], p[2]);
        cnt++;
    }

    for (ll n = 2; n < N; n++) {
        if (p[n] == n) {
            swap(p[n], p[n + 1]);
            cnt++;
        }
    }

    if (p[N] == N) {
        swap(p[N], p[N - 1]);
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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;
}

int main() {
  int n;
  cin >> n;
  vector<string> W(n);
  rep(i, n) cin >> W[i];
  set<string> st;
  rep(i, n) {
    st.insert(W[i]);
  }
  if(st.size() != n) {
    cout << "No" << endl;
    return 0;
  }
  rep(i, n - 1) {
    if(W[i][W[i].size() - 1] != W[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.*;

/**
 * Created by Ayushi on 13 Jun 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        br.close();
        System.out.println(s.substring(0, 3));
    }
}


Measured memory_bytes: 32304
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                return;
            }
            int w = sc.nextInt();
            int h = sc.nextInt();
            int[][] map = new int[h][w];
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt() - 1;
                int y = sc.nextInt() - 1;
                map[y][x] = 1;
            }
            int s = sc.nextInt();
            int t = sc.nextInt();
            int max = 0;
            int[][] rbmap = new int[h][w];
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    rbmap[i][j] = map[i][j];
                    if (i == 0 && j == 0) {
                    } else if (i == 0) {
                        rbmap[i][j] += rbmap[i][j - 1];
                    } else if (j == 0) {
                        rbmap[i][j] += rbmap[i - 1][j];
                    } else {
                        rbmap[i][j] += rbmap[i - 1][j] + rbmap[i][j - 1] - rbmap[i - 1][j - 1];
                    }
                }
            }
            // arrayDump(rbmap);
            for (int i = 0; i <= h - t; i++) {
                for (int j = 0; j <= w - s; j++) {
                    int c = rbmap[i + t - 1][j + s - 1];
                    if (i == 0 && j == 0) {
                    } else if (i == 0) {
                        c -= rbmap[i + t - 1][j - 1];
                    } else if (j == 0) {
                        c -= rbmap[i - 1][j + s - 1];
                    } else {
                        c += - rbmap[i + t - 1][j - 1] - rbmap[i - 1][j + s - 1] + rbmap[i - 1][j - 1];
                    }
                    // System.out.print(c + " ");
                    max = Math.max(c, max);
                }
                // System.out.println();
            }
            System.out.println(max);
        }
    }
    public static void arrayDump(int[][] a) {
        for (int i = 0, l = a.length; i < l; i++) {
            for (int j = 0, l2 = a[0].length; j < l2; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }
}

Measured memory_bytes: 41640
import java.util.*;
public class Main {
	public static void main(String [] args){
		Scanner s = new Scanner(System.in);
		String input = s.nextLine();
		char[] chars = input.trim().toCharArray();
		boolean prevBlack = (chars[0] == 'B'); 
		int result = 0;
		//find blocks 
		for (int i = 0; i < chars.length; i++){
			if (prevBlack && chars[i] == 'B') continue; 
			if ((!prevBlack) && chars[i] == 'W') continue;
			if (chars[i] == 'B') prevBlack = true;
			if (chars[i] == 'W') prevBlack = false;
			result++;
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 26304
#include <queue>
#include <stdio.h>

using namespace std;

int N;
int M;

std::priority_queue<int> pq;

int main(void){
    scanf("%d %d",&N,&M);
    int x;
    for(int i=0;i<N;i++){
        scanf("%d",&x);
        pq.push(x);
    }
    long long sum=0;
    for(int i=0;i<M;i++){
        int price = pq.top(); pq.pop();
        price /= 2;
        pq.push(price);
    }
    for(int i=0;i<N;i++){
        sum += pq.top();
        pq.pop();
    }
    printf("%lld\n",sum);
    return(0);
}

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

int main(void){
    int a,b,c,ans = 3;
    cin >> a >> b >> c;
    if(a == b)ans -= 1;
    if(b == c)ans -= 1;
    if(a == c)ans -= 1;
    if(ans == 0)ans += 1;
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S;
  cin >> S;
  ll res = 0;
  for (int k = 0; k < (1 << ((int)S.size() - 1)); k++) {
    ll a = S[0] - '0';
    for (int i = 0; i < (int)S.size() - 1; i++) {
      if ((k >> i) & 1) {
        res += a;
        a = 0;
      }
      a *= 10;
      a += S[i + 1] - '0';
    }
    res += a;
  }
  cout << res << '\n';
  return 0;
}


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

int main(){
  int mxA[101][101], mxB[101][101], n, m, l, el;
  long long res;

  cin >> n >> m >> l;

  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      cin >> mxA[i][j];
    }
  }

  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= l; j++){
      cin >> mxB[i][j];
    }
  }

  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= l; j++){
      res = 0;
      for(int k = 1; k <= m; k++){
        res += mxA[i][k] * mxB[k][j];
      }
      if( j == l) cout << res << endl;
      else cout << res << ' ';
    }
  }

  return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int h, w;
  cin >> h >> w;
  int a[505][505] = {};
  REP(i, h) {
    REP(j, w) { cin >> a[i][j]; }
  }
  vector<string> ans;
  REP(i, h) {
    REP(j, w) {
      if (a[i][j] % 2 == 1) {
        // 右下
        if (i == h - 1 && j == w - 1) break;
        // 一番右
        if (j == w - 1) {
          ans.push_back(to_string(i + 1) + " " + to_string(j + 1) + " " +
                        to_string(i + 2) + " " + to_string(j + 1));
          // 移動元はもう見ないので無視
          a[i + 1][j]++;
        } else {
          ans.push_back(to_string(i + 1) + " " + to_string(j + 1) + " " +
                        to_string(i + 1) + " " + to_string(j + 2));
          // 移動元はもう見ないので無視
          a[i][j + 1]++;
        }
      }
    }
  }

  cout << ans.size() << endl;
  for (auto s : ans) {
    cout << s << endl;
  }
}

Measured memory_bytes: 8452
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int main(){
	string S;
	cin>>S;
	//string S2=S;
	//S2=S2.reverse();
	bool check=true;
	REP(i,S.size()){
	    if(abs(S[i]-S[S.size()-i-1])>2)check=false;
	    if(S[i]==S[S.size()-i-1])check=false;
	}
	if(check){
           cout<<"Yes"<<endl;
        }else{
           cout<<"No"<<endl;
        }
	return(0);
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int, C: int, D: int):
    if A+B < C+D:
        print("Right")
    elif A+B == C+D:
        print("Balanced")
    else:
        print("Left")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		final int n = sc.nextInt();
		String ans = null;

		switch (n % 10) {
		case 3:
			ans = "bon";
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			ans = "pon";
			break;
		default:
			ans = "hon";
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 35876
import sys
n = int(input())  
w = [input() for i in range(n)]


if len(w) != len(set(w)):
    print('No')
    sys.exit()
else:
    for i, name in enumerate(w):

        try:
            if name[-1] != w[i+1][0]:
                print('No')
                sys.exit()

        except IndexError:
            print('Yes')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;

LL mpow(LL x, LL n){
    LL ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}
LL kj(LL x){
    LL s = 1;
    for(LL i = 1; i <= x; i++){
        s = s * i % MOD;
    }
    return s;
}


LL combination(LL a, LL b){
    if(a == 0 && b == 0) return 1;
    if(a < b || a < 0) return 0;
    return (kj(a) * mpow(kj(b), MOD-2) % MOD) * mpow(kj(a-b), MOD-2) % MOD;
}

int main(){
    LL n, k;
    cin >> n >> k;
    LL x = n - k;
    for(LL i = 1; i <= k; i++){
        cout << combination(x+1, i) * combination(k-1, i-1) % MOD << endl;
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

class Main{

	static String[] str = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

	public static void main(String[] args){

		Scanner scan = new Scanner(System.in);

		String str2 = scan.next();
		String[] str3 = str2.split("");

		for(int i=0;i<str3.length;i++){
			for(int j=0;j<26;j++){
				if(str3[i].equals(str[j])){
					int a = j-3;
					if(a<0){
						a=26+a;
					}
					System.out.print(str[a]);
				}
			}
		}

		System.out.println("");
	}			

}

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

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

#define N 1000000007
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

ll power(ll x, ll n) {
    ll ans = 1;
    while (n > 0) {
        if (n % 2 == 1) {
            ans *= x;
            ans %= N;
        }
        x *= x;
        x %= N;
        n >>= 1;
    }
    return ans;
}

ll comb(ll n, int a) {
    ll acc = 1;
    for (int i = 0; i < a; i++) {
        acc *= n - i;
        acc %= N;
    }
    ll div = 1;
    for (int i = 0; i < a; i++) {
        div *= i + 1;
        div %= N;
    }
    div = power(div, N - 2);
    return (acc * div) % N;
}

int main()
{
    int s;
    cin >> s;
    ll ans = 0;

    for (int i = 1; i <= s / 3; i++) {
        ans += comb(s - 3 * i + (i - 1), i - 1);
        ans %= N;
    }

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

Measured memory_bytes: 3612
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define L (x<<1)
#define R (x<<1|1)
#define mid ((l+r)>>1)
#define inf 0x3f3f3f3f3f3f3f3fll
#define MM (1<<20)
#define MN 200005
using namespace std;
inline int in(){
    int x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll ml[MM],mr[MM],mv[MM],tag[MM];
ll val,d;
int n,q,a,b,x,y;
inline void up(int x){
	ml[x]=min(ml[L],ml[R]);
	mr[x]=min(mr[L],mr[R]);
	mv[x]=min(mv[L],mv[R]);
}
inline void pushdown(int x,int l,int r){
	if (l==r||(!tag[x])) return;
	ml[L]+=tag[x];mr[L]+=tag[x];mv[L]+=tag[x];tag[L]+=tag[x];
	ml[R]+=tag[x];mr[R]+=tag[x];mv[R]+=tag[x];tag[R]+=tag[x];tag[x]=0;
}
inline void build(int x,int l,int r){
	if (l==r){
		mv[x]=inf;ml[x]=mv[x]+l;mr[x]=mv[x]-l;return;
	}build(L,l,mid);build(R,mid+1,r);up(x);
}
inline void update(int x,int l,int r,int p,ll v){
	if (l==r){
		mv[x]=min(mv[x],v);ml[x]=mv[x]+l;mr[x]=mv[x]-l;return;
	}pushdown(x,l,r);
	if (p<=mid) update(L,l,mid,p,v);
	else update(R,mid+1,r,p,v);up(x);
}
inline ll query1(int x,int l,int r,int a,int b){
	if (a<=l&&b>=r) return ml[x];pushdown(x,l,r);
	if (b<=mid) return query1(L,l,mid,a,b);
	if (a>mid) return query1(R,mid+1,r,a,b);
	return min(query1(L,l,mid,a,mid),query1(R,mid+1,r,mid+1,b));
}
inline ll query2(int x,int l,int r,int a,int b){
	if (a<=l&&b>=r) return mr[x];pushdown(x,l,r);
	if (b<=mid) return query2(L,l,mid,a,b);
	if (a>mid) return query2(R,mid+1,r,a,b);
	return min(query2(L,l,mid,a,mid),query2(R,mid+1,r,mid+1,b));
}
int main()
{
	n=in();q=in();a=in();b=in();
	build(1,1,n);update(1,1,n,b,0);y=a;
	for (int i=1;i<=q;++i){
		x=in();
		val=min(query2(1,1,n,1,x)+x,query1(1,1,n,x,n)-x);
		d=abs(x-y);ml[1]+=d;mr[1]+=d;mv[1]+=d;tag[1]+=d;
		update(1,1,n,y,val);y=x;
	}printf("%lld",mv[1]);return 0;
}

Measured memory_bytes: 24704
package main

import (
  "fmt"
  "strings"
)

func main() {
  var a, b, c string
  
  fmt.Scanf("%s %s %s", &a, &b, &c)
  
  ans := a[:1] + b[:1] + c[:1]
  ans = strings.ToUpper(ans)
  fmt.Printf("%s", ans)
}

Measured memory_bytes: 1844
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    string s;
    cin >> s;
    int sum = 0;
    for( int i = s.size() - 1; i > 0; --i ) {
        if( s[i] != '9' ) {
            s[i - 1]--;
            sum += 9;

        } else {
            sum += 9;
        }
    }
    cout << sum + ( s[0] - '0' ) << endl;
    return 0;
}


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

ll N, M, p,ans2=0, ans1=0;
string str;
set<ll> S;
map<ll, ll> MA;
signed main(){
    cin >> N >> M;
    for(int i=0;i<M;i++) {
        cin >> p >> str;
        if(str[0]=='A') S.insert(p);
        else if(S.find(p)==S.end()) MA[p]++;
    }
    for(set<ll>::iterator it=S.begin();it!=S.end();it++) {
        ans1 += MA[*it];
        ans2++;
    }
    cout << ans2 << " " << ans1 << endl;
    return 0;
}

Measured memory_bytes: 14472
//
//  main.cpp
//  160324
//
//  Created by ?加寿 on 16/3/24.
//  Copyright ? 2016年 chenhuan001. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

#define N 110
map<string,int> cao;

string saves[N];
int savek[N];
int main(int argc, const char * argv[]) {
    int n;
    int tt=1;
    while(cin>>n&&n)
    {
        cao.clear();
        for(int i=0;i<n;i++)
        {
            string tmp;
            int key;
            cin>>tmp>>key;
            saves[i] = tmp;
            savek[i] = key;
            cao[tmp] = max(cao[tmp],key);
        }
        //第一个背包
        char g[222];
        scanf("%s",g);
        int len=strlen(g);
        int dp[22200];
        memset(dp,-1,sizeof(dp));
        dp[0]=0;
        for(int i=0;i<len;i++)
        {
            //?个地方有点??
            //dp[i+1] = max(dp[i+1],dp[i]);
            if(dp[i]==-1)
            {
                continue;
            }
            string str="";
            for(int j=i;j<len;j++)
            {
                str+=g[j];
                if(cao[str] != 0)
                {
                    dp[j+1] = max(dp[j+1],dp[i]+cao[str]);
                }
            }
        }
        int mx=dp[len];
        //再用2000的背包.
        for(int i=0;i<2002;i++)
            dp[i] = 1e6;
        dp[0] = 0;
        //无限背包
        for(int i=0;i<mx;i++)
        {
            for(int j=0;j<n;j++)
            {
                int sz=saves[j].length();
                dp[ i+savek[j] ] = min(dp[i+savek[j]],dp[i]+sz);
            }
        }
        printf("Case %d: ",tt++);
        cout<<dp[mx]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5404
#include <stdio.h>
#include <algorithm>
#include <vector>

std::vector<int> d,t;
int n,m;
int main()
{
    scanf("%d",&n);
    d.resize(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&d[i]);
    }
    scanf("%d",&m);
    t.resize(m);
    for(int i=0;i<m;i++)
    {
        scanf("%d",&t[i]);
    }
    std::sort(d.begin(), d.end());
    std::sort(t.begin(), t.end());
    int prob = 0;
    for(int i=0;i<n;i++)
    {
        if(d[i] == t[prob])
            prob++;
        if(prob == m) break;
    }
    if(prob == m) puts("YES");
    else puts("NO");
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int n;
int l = 0;

int main(){
  cin >> n;
  int tmp = n;
  while(tmp/10 || tmp%10){
    l += tmp % 10;
    tmp /= 10;
  }
  if(n%l) cout << "No" <<endl;
  else cout << "Yes" <<endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
cnt={'R':0,'B':0,'G':0}
ans=1
for i in range(n):
    count=0
    num=0
    for j in 'RBG':
        if cnt[j]==a[i]:
            count+=1
            if num==0:
                cnt[j]+=1
                num=1
    ans*=count
print(ans%(10**9+7))

Measured memory_bytes: 13964
#include <bits/stdc++.h>
#define X1 first.first
#define Y1 first.second
#define X2 second.first
#define Y2 second.second
using namespace std;
int n, m, t[512][512];
vector<pair<pair<int,int>,pair<int,int>>> wynik;

int main()
{
    cin>>n>>m;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            cin>>t[i][j];
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(i == n && j == m) break;
            if(t[i][j] % 2 == 0) continue;
            if(j == m)
            {
                wynik.push_back({{i, j}, {i + 1, j}});
                t[i + 1][j]++;
            }
            else
            {
                wynik.push_back({{i, j}, {i, j + 1}});
                t[i][j + 1]++;
            }
        }
    }
    cout<<wynik.size()<<endl;
    for(auto ruch: wynik)
    {
        cout<<ruch.X1<<" "<<ruch.Y1<<" "<<ruch.X2<<" "<<ruch.Y2<<endl;
    }
}


Measured memory_bytes: 5232
#include "bits/stdc++.h"
using namespace std;
 
// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
 
/*
--------------------------------------------
 
	type
 
--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;
 
/*
--------------------------------------------
 
	container
 
--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
 
/*
--------------------------------------------
 
	repetition
 
--------------------------------------------
*/
#define MAX(a,b) (a>b)?a:b
#define MIN(a,b) (a>b)?b:a
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPS(i,n) for(int i=0; i<(n); i++)
#define REPinit(a,n) for(int i=a; i<(n); i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)
 
//algorithm
//#define SORT(c) sort((c).begin(),(c).end())
 
/*
--------------------------------------------
 
	constant
 
--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
/*
 
	Optimizer
 
*/
//#pragma GCC optimize("Ofast")


/*
 
	Utility Algorithm
 
*/
template <typename T>
void swapAlgorithm(T& a, T& b) {
    T tmp = a;
    a = b;
    b = tmp;
}

LL euclideanAlgorithm(LL a, LL b) {
    LL a_tmp = a;
    LL b_tmp = b;

    if (a_tmp > b_tmp) {
        swapAlgorithm<LL>(a_tmp, b_tmp);
    }

    LL r = a_tmp % b_tmp;
    while (r != 0) {
        a_tmp = b_tmp;
        b_tmp = r;
        r = a_tmp % b_tmp;
    }
    return b_tmp;    
}

LL getLCM(LL a, LL b) {
    return (a * b)/(euclideanAlgorithm(a, b));
}

/*
  Code
*/

double eauclidDistance(pair<double, double>& x1, pair<double, double>& x2) {
  return sqrt((x1.first - x2.first) * (x1.first - x2.first) + (x1.second - x2.second) * (x1.second - x2.second));
}

void swap(int& a, int& b) {
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

int main(int argc, char const *argv[])
{
  int N,A;
  cin >> N >> A;

  N %= 500;

  if(N <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 384
# '重複する要素があると条件から逸脱する' と '他の要素が約数になると条件から逸脱する' 
# 上記2つの問題を 前半と後半に分けて処理する、

n = int(input())
l = list(map(int,input().split()))

# 重複問題
num = max(l)+1
rcd = [0 for _ in range(num)] # indexを数列Aと読み替え可能な配列として初期化

for v in l: # 重複する配列を区別するため各要素数をカウントして...
    rcd[v] += 1

unq = []
for w in range(num): # 重複がない要素のみ'unq'に集約
    if rcd[w] == 1: # 1個の場合のみが該当
        unq.append(w)
#print(unq)

# 約数問題
rcd = [0 for _ in range(num)] # 再度初期化
l = set(l) # ここでは重複を考慮しないため集合化
for x in l: # 自身以外の約数の有無を確認するためのループ
    for y in range(2*x, num, x): # ※自身を約数としてカウントしない工夫！
        rcd[y] = 1 # 自身以外の約数がある場合は'1'が代入される
#print(rcd)

# まとめ
ans = 0
for z in unq: # 'unq'の中で...
    if rcd[z] == 0: # 自身以外に約数を持たない要素のみを...
        ans += 1 # カウント
print(ans)


Measured memory_bytes: 47556
n,m = gets.split.map(&:to_i)

cnt = [1]*n
mayred = [false]*n
mayred[0] = true

m.times{
	x,y=gets.split.map(&:to_i)
	x-=1
	y-=1
	cnt[x]-=1
	cnt[y]+=1
	mayred[y] ||= mayred[x]
	mayred[x] = false if cnt[x]==0
}
puts mayred.count{|b| b }


Measured memory_bytes: 3324
import java.util.*;

public class Main {

	private static List<Integer> getStrings(Scanner sc, int num) {
		List<Integer> stringList = new ArrayList<>();
		while(num>0) {
			int nextInt = sc.nextInt();
			stringList.add(nextInt);
			num--;
		}
		return stringList;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		List<Integer> alist = getStrings(sc, n);
		int sum = alist.stream().mapToInt(t -> t).sum();
		Collections.sort(alist);
		Collections.reverse(alist);
		for (int i = 0; i < m; i++) {
			if (alist.get(i) * 4 * m / sum < 1) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}

}


Measured memory_bytes: 28884