akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = [list(map(int, input().split())) for _ in range(N)]
size = 1<<N
dp = [0]*size
cost = [0]*size
s_to_i = {1<<i:i for i in range(N)}
for s in range(size):
    for i in range(N):
        for j in range(i+1, N):
            if 1<<j & s and 1<<i & s:
                cost[s]+=a[i][j]

for s in range(1, size):
    sub = s
    while sub>=0:
        sub&=s
        dp[s] = max(dp[s^sub]+cost[sub], dp[s])
        sub-=1
print(dp[-1])

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

int main() {
  string a, b, c;
  locale l = locale::classic();
  cin >> a >> b >> c;
  cout << toupper(a[0], l) << toupper(b[0], l) << toupper(c[0], l) << "\n";

  return(0);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define print(x) printf("%d",x)
#define scan(x) scanf("%d",&x)
#define printn(x) printf("%d\n",x)
#define rep(i,n,m) for(int i = n; i < m; i++)

int main(void){
	int flag = 1;
	int i;
	int n;
	int ex;
	int a[100];
	int count = 0;
	scan(n);
	rep(i,0,n){
		scan(a[i]);
	}
	i = 0;
	while(flag){
		flag = 0;
		for(int j = n-1; j > i; j--){
			if(a[j] < a[j-1]){
				ex = a[j];
				a[j] = a[j-1];
				a[j-1] = ex;
				flag = 1;
				count++;
			}
		}
		i++;
	}
	rep(i,0,n){
		print(a[i]);
		if(i != n-1){
			printf(" ");
		}
	}
	printf("\n");
	printn(count);
	return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>

char A[5]={'A','C','G','T'};

int hikaku(char b){
    for (int i=0; i<4; i++) {
        if(b==A[i]){
            return 1;
        }
    }
    return 0;
}

int main(void){
    char S[10];
    scanf("%s",S);
    int i,j,k,max=0;
    for (i=0; S[i]!='\0'; i++) {
        if(hikaku(S[i])){
            k=0;
            for (j=i; S[j]!='\0'; j++) {
                if(hikaku(S[j])){
                    k++;
                }
                else{
                    break;
                }
                if (k>max) {
                    max=k;
                }
            }
        }
    }
    printf("%d\n",max);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vvll vector<vll>
#define wh(t) while(t--)
#define fi(n) for(ll i = 0; i < n; i++)
#define fj(n) for(ll j = 0; j < n; j++)
#define fu(i,s,e) for(ll i = s; i <=e; i++)
#define fd(i,s,e) for(ll i = s; i >=e; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fr first
#define se second
#define sll stack<ll>
#define qll queue<ll>
using namespace std;
const ll M = 1e9+7;
//const ll M = 998244353;

ll pmp(ll x,ll n){ll a = 1;while(n > 0){if(n & 1) a = (a * x)%M;x = (x * x)%M;n = n>>1;}return a;}

void solve(){
	ll x;
	cin >> x;
	if(x < 30) cout << "No\n";
	else cout << "Yes\n";
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif
	ll t;
	t = 1;
	//cin >> t;
	wh(t){
		solve();
	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




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

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/



Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Node{
	bool operator<(const struct Node &arg) const{
		return weight < arg.weight;
	};
	int from,to,weight;
};

int parent[101],height[101];

int getParent(int id){
	if(parent[id] == id)return id;
	else{
		return parent[id] = getParent(parent[id]);
	}
}

bool isSame(int a, int b){
	return getParent(a) == getParent(b);
}

void unite(int a,int b){
	int a_parent = getParent(a);
	int b_parent = getParent(b);

	if(a_parent == b_parent)return;

	if(height[a_parent] > height[b_parent]){
		parent[b_parent] = a_parent;
	}else{
		if(height[a_parent] == height[b_parent])height[b_parent]++;
		parent[a_parent] = b_parent;
	}
}


int main(){

	int V,E,ans,maximum,minimum;
	bool FLG;
	Node nodes[4950];

	while(true){
		scanf("%d %d",&V,&E);
		if(V == 0 && E == 0)break;

		for(int i = 1; i <= V; i++){
			parent[i] = i;
			height[i] = 0;
		}

		for(int i = 0; i < E; i++){
			scanf("%d %d %d",&nodes[i].from,&nodes[i].to,&nodes[i].weight);
		}

		sort(nodes,nodes+E);

		maximum = 0;
		minimum = BIG_NUM;

		for(int i = 0; i < E; i++){
			if(!isSame(nodes[i].from,nodes[i].to)){
				maximum = max(maximum,nodes[i].weight);
				minimum = min(minimum,nodes[i].weight);
				unite(nodes[i].from,nodes[i].to);
			}
		}

		FLG = true;
		for(int i = 2; i <= V; i++){
			if(!isSame(1,i)){
				FLG = false;
				break;
			}
		}

		if(!FLG){
			printf("-1\n");
			continue;
		}

		ans = maximum - minimum;

		//start?????°???????????????
		for(int start = 0; start < E;start++){
			for(int end = start; end < E; end++){

				for(int i = 1; i <= V; i++){
					parent[i] = i;
					height[i] = 0;
				}

				maximum = 0;
				minimum = BIG_NUM;

				for(int i = start;i <= end;i++){
					if(!isSame(nodes[i].from,nodes[i].to)){
						maximum = max(maximum,nodes[i].weight);
						minimum = min(minimum,nodes[i].weight);
						unite(nodes[i].from,nodes[i].to);
					}
				}

				FLG = true;
				for(int i = 2; i <= V; i++){
					if(!isSame(1,i)){
						FLG = false;
						break;
					}
				}

				if(FLG){
					ans = min(ans,maximum-minimum);
					break;
				}
			}
		}

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

	return 0;
}

Measured memory_bytes: 2632
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

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

    map <int, int> m;

    int count = 0;
    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        if (m[a] == 0){
            count ++ ;
        }
        m[a] ++;
    }

    vector <int> A(count);
    count = 0;
    for (int i = 1; i <= N; i++){
        if (m[i] != 0){
            A[count] = m[i];
            count ++;
        }        
    }
    
    int ans = 0;
    if (count > K){
        sort(A.begin(), A.end());
        for (int i = 0; i < count - K; i++){
            ans += A[i];
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10368
while True:
  px, py = map(int, input().split())
  if px == 0:
    break

  n = int(input())
  pairs = list(map(int, input().split()))
  s_points = []
  for i in range(n):
    s_points.append((pairs[i * 2], pairs[i * 2 + 1]))
  
  survive_range = [(x, y) for x in (-1, 0, 1) for y in (-1, 0, 1)]
  jump_to = ((-2, -1), (-2, 0), (-2, 1), (-1, -2), (-1, 2), (0, -2), (0, 2), 
               (1, -2), (1, 2), (2, -1), (2, 0), (2, 1))

  def next_points(p):
    x, y = p
    return {(x + dx, y + dy) for dx, dy in jump_to if 0 <= x + dx <= 9 and 0 <= y + dy <= 9}

  def survive_points(p):
    x, y = p
    return {(x + dx, y + dy) for dx, dy in survive_range if 0 <= x + dx <= 9 and 0 <= y + dy <= 9}
  
  def next_survive(ps):
    ret = set()
    for p in ps:
      ret = ret | next_points(p)
    return ret

  survive ={(px, py)}
  for sp in s_points:
    i_survive = survive_points(sp)
    survive = next_survive(survive) & i_survive
  
  if survive:
    print("OK")
  else:
    print("NA")


Measured memory_bytes: 5620
package main

import "fmt"

func main() {
	var s, ans string
	fmt.Scan(&s)
	if s == "Sunny" {
		ans = "Cloudy"
	} else if s == "Cloudy" {
		ans = "Rainy"
	} else {
		ans = "Sunny"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<stdio.h>

int main()
{
	int x,y,z;
	scanf("%d %d %d",&x,&y,&z);
	if (x>9 || x<1 || y>9 || y<1 || z>9 || z<1)
	{
		printf("Error!");
	}
	else if( x == y && y == z && x == z){
		printf("No");
	}
	else if (x == z || x == y || y == z){
		printf("Yes");
	}
	else if (x>y || z>x || y>z){
		printf("No");
	}	
}

Measured memory_bytes: 1720
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
#define INF (2e9)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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()
{
    string s; cin >> s;
    int n = s.size(); 
    set<char> chars;
    rep(i, n) chars.insert(s[i]);
    int ans = INF;
    string t;

    for(char e: chars){
        t = s;
        set<char> chart = chars;
        while(chart.size() > 1){
            string u;
            rep(i, t.size()-1){
                if(t[i]==e || t[i+1]==e) u.push_back(e);
                else u.push_back(t[i]);
            }
            t = u;
            chart.clear();
            rep(i, t.size()) chart.insert(t[i]);
        }
        chmin(ans, (int)s.size() - (int)t.size());
    }
    pr(ans);
    return 0;}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll k = 1; k < n; k++) {
        ll m = n / k - 1;
        if (k > m - 1) break;
        if (n % k == 0 and m >= 1) ans += m;
    }
    cout << ans << ln;
    return 0;
}


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

typedef pair<int, int> P;
typedef pair<int, P> T;
struct edge{
    int to, dist, cost;
};
const int MAX_N = 10005;
const int MAX_D = 1005;
const int INF = 2*MAX_N*MAX_D;
int N,M;  //N=都市の数,M=当初の道路の数
//int dist[MAX_N][MAX_N];
//int cost[MAX_N][MAX_N];
vector<edge> G[MAX_N];
int addi[MAX_N];
int d[MAX_N];

bool exist(int v, int pv) {
    bool ret = false;
    for (int i = 0; i < (int)G[pv].size(); i++) {
        edge e = G[pv][i];
        if (e.to == v) {
            ret = true;
            break;
        }
    }
    return ret;
}
int findCost(int v, int pv) {
    int ret = INF;
    for (int i = 0; i < (int)G[pv].size(); i++) {
        edge e = G[pv][i];
        if (e.to == v) {
            ret = e.cost;
            break;
        }
    }
    return ret;
}

int findDist(int v, int pv) {
    int ret = INF;
    for (int i = 0; i < (int)G[pv].size(); i++) {
        edge e = G[pv][i];
        if (e.to == v) {
            ret = e.dist;
        }
    }
    return ret;
}

int dijkstra(int s) {  //1~各地点間の最短の道路建設に必要な追加費用
    fill(d, d+N+1, INF);
    fill(addi, addi+N+1, INF);
    d[s] = 0;
    addi[s] = 0;
    priority_queue<T, vector<T>, greater<T> > pque;
    
    pque.push(T(0,P(s,s)));  //距離、現在地、前の点
    while (!pque.empty()) {
        T t = pque.top(); pque.pop();
        int v = t.second.first;
        if (d[v] < t.first) continue;
        int pv = t.second.second;
        //最短経路が複数あった場合は、追加のコストが小さい方を選ぶ
        if (addi[v] != 0 && findCost(v,pv) < addi[v]) {
            addi[v] = findCost(v,pv);
        }
        for (int i = 0; i < (int)G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] >= t.first + e.dist) {  //最短距離の更新
                d[e.to] = t.first + e.dist;
                pque.push(T(d[e.to],P(e.to,v)));
            }
        }
    }
    int total = 0;
    for (int i = 2; i <= N; i++) {
        total += addi[i];
    }
    return total;
}

int main(int argc, const char * argv[])
{
    while (true) {
        scanf("%d %d", &N, &M);
        if (N == 0 && M == 0) break;

        for (int i = 0; i < M; i++) {
            int u,v,d,c;
            scanf("%d %d %d %d", &u, &v, &d, &c);
            edge e1,e2;
            e1.to = v; e2.to = u;
            e1.dist = e2.dist = d;
            e1.cost = e2.cost = c;
            G[u].push_back(e1);
            G[v].push_back(e2);
            //dist[u][v] = dist[v][u] = d;
            //cost[u][v] = cost[v][u] = c;
        }
        int ret = 0;
        ret = dijkstra(1);
        printf("%d\n",ret);
        for (int i = 1; i <= N; i++) {
            G[i].clear();
        }
        
    }
    return 0;
}

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

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REPR(i,n) FORR(i,0,n)

int main() {
  
  
  int N; cin >> N;
  LL K; cin >> K;
  int M = 60;
  VI A(N);
  REP(i,N){
    cin >> A.at(i);
    A.at(i)--;
  }
  
  VVI next(M,VI(N));
  
  REP(i,N) next.at(0).at(i) = A.at(i);
  
  REP(i,M-1)REP(j,N){
    next.at(i+1).at(j) = next.at(i).at(next.at(i).at(j));
  }
  
  
  int ans=0;
  
  REPR(i,M){
    if((K>>i) & 1){
      ans = next.at(i).at(ans);
    }
  }
  
  cout <<(ans+1) << endl;
  
  
  
  return 0;
}


Measured memory_bytes: 51836
n = int(input())
lst = [int(input()) for _ in range(n)]
lst.sort()
if n%2==0:
    lower = lst[:n//2]
    upper = lst[n//2:]
    x = 2*sum(upper) - upper[0]
    y = 2*sum(lower) - lower[-1]
    print(x-y)
else:
    lower = lst[:n//2]
    upper = lst[n//2+1:]
    mid = lst[n//2]
    x = 2*sum(upper) - 2*sum(lower) - mid + lower[-1]
    y = 2*sum(upper) - 2*sum(lower) + mid - upper[0]
    print(max(x,y))

Measured memory_bytes: 7776
s = int(input())
a = s // 100
b = s % 100

if 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")
elif 1 <= a <= 12:
    print("MMYY")
elif 1 <= b <= 12:
    print("YYMM")
else:
    print("NA")

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, X;
  cin >> N >> X;

  VI xs(N);
  cin >> xs;
  SORT(xs);

  int ans = 0;
  for(auto x: xs){
	if(x <= X) ++ans;
	X = max(0, X-x);
  }

  if(X) --ans;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
alp="abcdefghijklmno"

def saiki(now,st,used):
    num=now-1
    if num==0:
        print(st)
    else:
        for i in range(used+1):
            if i==len(range(used+1))-1:
                saiki(now-1,st+alp[i],used+1)
            else:
                saiki(now-1,st+alp[i],used)

saiki(n,"a",1)

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 1e5 + 5;
int a[MAXN], sum[MAXN];
map <int, int> can;

signed main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif
  
  int n, m, v, p;
  read(n), read(m), read(v), read(p);
  for (RI i = 1; i <= n; ++i) read(a[i]);
  sort(a + 1, a + 1 + n);
  for (RI i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];
  for (RI i = n; i >= 1; --i) {
    if (a[i] + m < a[n - p + 1]) break;
    if (i + (p - 1) >= v) { can[a[i]] = 1; continue; }
    if (can[a[i]]) continue;
    LL res = (v - i - (p - 1)) * m;
    LL s = sum[n - (p - 1)] - sum[i];
    LL cnt = n - (p - 1) - i;
    if ((a[i] + m) * cnt >= s + res)
      can[a[i]] = 1;
    else break;
  }
  int ans = 0;
  for (RI i = 1; i <= n; ++i)
    if (can[a[i]]) ++ans;
  printf("%lld\n", ans);

  return 0;
}

// created by Daniel yuan

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

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない
const int maxn = 100000;
ll mod = INF;
int N;
string s;
string c;

bool jud(int N,char first,char last){
    c[0]=first;
    c[N-1]=last;
    rep(i,N){
        //cout <<"jud"<< i<<endl;
        int preidx = (N-1+i)%N;
        int next = (i+1)%N;
        if(c[i]=='W'&&s[i]=='o'){  //狼かつ両側違う
            if(c[preidx]=='W')c[next]='S';
            else c[next]='W';
        }else if(c[i]=='W'&&s[i]=='x'){//狼かつ両方同じ
            if(c[preidx]=='W')c[next]='W';
            else c[next]='S';
        }else if(c[i]=='S'&&s[i]=='o'){//羊かつ両方同じ
            if(c[preidx]=='W')c[next]='W';
            else c[next]='S';
        }else if(c[i]=='S'&&s[i]=='x'){//羊かつ両方違う
            if(c[preidx]=='W')c[next]='S';
            else c[next]='W';
        }
    }
    
    return last == c[N-1]&&c[0]==first;
}

int main(){
    cin >> N;
    cin >> s;
    c=s;
    //s[0]を狼、s[N-1]を狼とする
    //cout << 1<<endl;
    c[0]='W';
    c[N-1]='W';
    char last = 'W';
    if(jud(N,'W','W')){
        cout << c;
        cout <<endl;
        return 0;
    }
    //s[0]を狼、s[N-1]を羊とする
    //cout << 2<<endl;
    c[0]='W';
    c[N-1]='S';
    last = 'S';
    if(jud(N,'W','S')){
         cout << c;
         cout <<endl;
        return 0;
    }
    //s[0]を羊、s[N-1]を狼とする
    //cout << 3<<endl;
    c[0]='S';
    c[N-1]='W';
    last = 'W';
    if(jud(N,'S','W')){
         cout << c;
         cout <<endl;
        return 0;
    }
    
    //s[0]を羊、s[N-1]を羊とする
    //cout << 4<<endl;
    c[0]='S';
    c[N-1]='S';
    last = 'S';
    if(jud(N,'S','S')){
         cout << c;
         cout <<endl;
        return 0;
    }
    
    cout << -1<<endl;
    return 0;
}
    



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

int main() {

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


    int ans = 0;
    for(int i = 0; i < N; i++){
        int num = a[i];

        while(a[i] % 2 == 0 ){
            a[i] /= 2;
            ans++;
        }
    }

    cout << ans << endl;
    // int ans = 0;
    // while(1){
    //     vector<int> even_num;
    //     int Max = -1;

    //     for(int i = 0; i < N; i++){
    //         if(a[i] % 2 == 0){
    //             even_num.push_back(a[i]);
    //             Max = max(Max, a[i]);
    //         }
    //     }

    //     if(even_num.size() == 0)
    //         break;
        
    //     for(int i = 0; i < N; i++){
    //         if(a[i] == Max)
    //             a[i] /= 2;
    //         else
    //             a[i] *= 3;
    //     ans++;
    // }
    // cout << ans << endl;

    return 0;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 62;

int main() {
  int N, K;
  std::cin >> N >> K;

  std::vector<ll> H(N + 1);
  rep(i, N) {
    std::cin >> H[i + 1];
  }

  std::vector<std::vector<ll>> dp(N + 1, std::vector<ll>(N + 1, INF));
  for(int i = 0; i <= N; ++i) {
    dp[i][0] = 0;
    dp[i][1] = H[i];
  }
  for(int i = 1; i <= N; ++i) {
    for(int j = 2; j <= i; ++j) {
      for(int t = 1; t < i; ++t) {
        dp[i][j] = std::min(dp[i][j], dp[t][j - 1] + std::max(0LL, H[i] - H[t]));
      }
    }
  }

  ll ans = INF;
  for(int i = 1; i <= N; ++i) {
    ans = std::min(ans, dp[i][N - K]);
  }
  std::cout << ans << '\n';

}


Measured memory_bytes: 1024
N = int(input())
H = list(map(int,input().split()))
ans = 0
height = 10**9+1
cnt = 0
for i in range(N-1,-1,-1):
    if H[i] >= height:
        cnt += 1
    else:
        if ans < cnt:
            ans = cnt
        cnt = 0
    height = H[i]
if ans < cnt:
    ans = cnt
print(ans)

Measured memory_bytes: 14224
#include <vector>
#include <array>
#include <algorithm>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <math.h>
#include <assert.h>
#include <queue>
#include <deque>
#include <iomanip>
#include <numeric>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;

#define fi first
#define se second

#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll MAXN = (ll)2e5 + 228;
ll n, q;
bool used[MAXN];
vvl g(MAXN);
ll kek[MAXN];
ll ans[MAXN];

void dfs(ll v, ll x) {
    used[v] = true;
    x += kek[v];
    ans[v] = x;
    for (ll u : g[v]) {
        if (used[u]) continue;
        dfs(u, x);
    }
}

int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n >> q;
    for (int i = 0; i < n - 1; ++i) {
        ll v, u;
        cin >> v >> u;
        --v, --u;
        g[v].pb(u), g[u].pb(v);
    }

    for (int i = 0; i < q; ++i) {
        ll p, x;
        cin >> p >> x;
        --p;
        kek[p] += x;
    }

    dfs(0, 0);

    for (int i = 0; i < n; ++i) {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 22656
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)

r = []
i = 0
while i < n:
    if i < n - 1 and a[i] == a[i + 1]:
        r.append(a[i])
        i += 2
    else:
        i += 1
    if len(r) == 2:
        break
if len(r) == 2:
    print(r[0] * r[1])
else:
    print(0)

Measured memory_bytes: 14252
using System;
using System.Collections.Generic;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            if(S.EndsWith("s"))
            {
                Console.WriteLine(S + "es");
            } else
            {
                Console.WriteLine(S + "s");
            }
        }
    }
}

Measured memory_bytes: 26100
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
lli maxy = 10;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,k;
    cin>>n>>k;
    lli a[n];
    lli mul = 1;
    for(lli i=0;i<n;i++)
    	{
    		cin>>a[i];
    		a[i] = a[i];
    	}
    lli j = 0;
    for(lli i=k;i<n;i++)
    {
    	if(a[i]>a[j])
    		{
    		    cout<<"Yes\n";//<<mul<<" "<<prev<<"\n";
    		}
    	else
    		cout<<"No\n";//<<mul<<" "<<prev<<"\n";
    	j++;
    }
    return 0;
}

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

template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G,T INF){
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
	d[u]=d[v]+c;
	b[u]=v;
	q.emplace(d[u],u);
      }
    }
  }
  return d;
}


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

//INSERT ABOVE HERE
signed main(){
  Int n,m,c;
  cin>>n>>m>>c;
  using P = pair<Int, Int>;
  vector<vector<P > > G(n);
  Int sum=0;
  for(Int i=0;i<m;i++){
    Int a,b,d;
    cin>>a>>b>>d;
    a--;b--;
    G[a].emplace_back(b,d);
    G[b].emplace_back(a,d);
    sum+=d;
  }
  const Int INF = 1e15;
  auto d=dijkstra(0,G,INF);

  vector<Int> ord(n);
  iota(ord.begin(),ord.end(),0);
  sort(ord.begin(),ord.end(),
       [&](auto a,auto b){
	 return d[a]<d[b];
       });

  vector<Int> used(n,0);
  auto calc=[&](Int v){
    for(auto e:G[v]){
      Int u,d;
      tie(u,d)=e;
      if(used[u]) sum-=d;
    }
    used[v]=1;
  };

  Int ans=sum;
  for(Int i=0;i<n;){
    Int x=d[ord[i]];
    while(i<n&&d[ord[i]]==x) calc(ord[i++]);
    //cout<<x<<":"<<x*c<<" "<<sum<<":"<<x*c+sum<<endl;
    chmin(ans,x*c+sum);
  }
  //assert(sum==0);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 18100
while True:
  n = int(input())
  if n == 0:
    break
  hr_lst = []
  for _ in range(n):
    h, r = map(int, input().split())
    hr_lst.append((h, r))
  
  m = int(input())
  for _ in range(m):
    h, r = map(int, input().split())
    hr_lst.append((h, r))
  
  hr_lst.sort(reverse=True)

  r_lst = [[] for _ in range(1001)]
  for h, r in hr_lst:
    r_lst[h].append(r)
  r_lst = [lst for lst in r_lst if lst != []]
  
  """
  dp[y] ... 最大yまでの最大入れ子数
  dp[y] = max(dp[y], dp[v - 1] + 1)
  """
  dp = [0] * 1001
  for x in range(len(r_lst)):
    vlst = r_lst[x]
    max_v = 1000
    for v in vlst:
      dpv1 = dp[v - 1] + 1
      for y in range(max_v, v - 1, -1):
        if dp[y] < dpv1:
          dp[y] = dpv1
  print(dp[1000])


Measured memory_bytes: 5640
n,y = map(int,input().split())
flag = 0
for i in range(int(y/10000 +1)):
    #i:10000
    if flag == 0:
        for j in range(int(y/5000 + 1)):
            #j:5000
            k = n - i - j
            if(k < 0):
                continue
            else:
                if(y == 10000*i + 5000*j + 1000*k):
                    print(i,j,k)
                    flag = 1
                    break
    else:break
if flag == 0:
    print("-1 -1 -1")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
char s[100020];
int main() {
	scanf("%s", s);
	for (int i = 0; s[i]; i++) {
		if (s[i] == s[i + 1]) {
			printf("%d %d\n", i + 1, i + 2);
			return 0;
		}
		if (s[i] == s[i + 2]) {
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n,k; string s;
  cin>>n>>k>>s;

  vi C;
  int now = 1;
  int cnt = 0;
  rep(i, n){
    if(s[i] == char('0' + now)) cnt++;
    else{
      C.pb(cnt);
      now = 1 - now;
      cnt = 1;
    }
  }
  C.pb(cnt);
  if(C.size()%2 == 0) C.pb(0);
  int m = C.size();
  vi S(m+1); rep(i, m) S[i+1] = S[i] + C[i];
  int ans = 0;
  for (int i = 0; i < m; i+=2) {
    chmax(ans, S[min(i+2*k+1,m)]-S[i]);
  }

  std::cout << ans << '\n';
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    string expr; cin >> expr;
    int ans; cin >> ans;

    char res = 'I';

    int sum = expr[0] - '0';
    range(i, 1, expr.size()){
        if(expr[i++] == '+'){
            sum += expr[i] - '0';
        }
        else sum *= expr[i] - '0';
    }
    if(ans == sum) res = 'L';

    sum = 0;
    vi nums;
    nums.pb(expr[0] - '0');
    range(i, 1, expr.size()){
        if(expr[i++] == '+'){
            nums.pb(expr[i] - '0');
        }
        else nums[nums.size() - 1] *= expr[i] - '0';
    }
    each(itr, nums){
        sum += *itr;
    }
    if(ans == sum){
        res = res == 'L' ? 'U':'M';
    } 

    cout << res << endl;

	return 0;
}

Measured memory_bytes: 1216
def main():
    S = input()
    ACGT = {'A', 'C', 'G', 'T'}
    ans, s_l = 0, 0
    for c in S:
        if c in ACGT:
            s_l += 1
        else:
            ans = max(ans, s_l)
            s_l = 0
    ans = max(ans, s_l)
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

long long n, m, x;
long long c[20], a[20][20];
long long go[20];
long long minn = 19876543210;

void f(long long here)
{
	if(here >= n)
	{
		long long ji[20] = {0, };
		long long co = 0;
		
		for(long long i = 0 ; i < n ; i++)
		{
			if(go[i] == 0)
				continue;
			
			for(long long j = 0 ; j < m ; j++)
				ji[j] += a[i][j];
			
			co += c[i];
		}
		
		long long ff = 0;
		
		for(long long i = 0 ; i < m ; i++)
		{
			if(ji[i] < x)
				ff = 1;
		}
		
		if(ff == 0)
			minn = min(minn, co);
		
		return;
	}
	
	go[here] = 0;
	f(here + 1);
	go[here] = 1;
	f(here + 1);
}

int main(void)
{
	scanf("%lld %lld %lld", &n, &m, &x);
	
	for(long long i = 0 ; i < n ; i++)
	{
		scanf("%lld", &c[i]);
		
		for(long long j = 0 ; j < m ; j++)
			scanf("%lld", &a[i][j]);
	}
	
	f(0);
	
	printf("%lld", minn == 19876543210 ? -1 : minn);
	return 0;
}

Measured memory_bytes: 3828
#include <iostream>  
#include <cstdio>  
#include <algorithm>
#include <vector>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <math.h>
#include <sstream>
using namespace std;
#define lld long long
int f[105];
int main() {
	memset(f, 0, sizeof(f));
	int a, b, c;
	cin >> a >> b >> c;
	int sum = a;
	while (1) {
		int remain = sum % b;
		if (remain == c) {
			cout << "YES" << endl;
			break;
		}
		if (f[remain] == 1) {
			cout << "NO" << endl;
			break;
		}
		f[remain] = 1;
		sum += a;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
 
n = int(input())
a = list(map(int, input().split()))
q = int(input())
 
total = sum(a)
 
numbers = defaultdict(int)
 
for item in a:
    numbers[item] += 1
    
for i in range(q):
    b, c = map(int, input().split())
    taken = numbers[b]
    total -= numbers[b]*b
    numbers[c] += numbers[b]
    numbers[b] = 0
    total += taken*c
    print(total)

Measured memory_bytes: 89744
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  int a1[n],a2[n],b1[n],b2[n],l[m],c=0;
  r(i,n)cin>>a1[i],a2[i]=a1[i];
  r(i,m)cin>>l[i];
  r(i,n){
    for(int p=0;p<l[c];p++,i++)
      b1[i]=c%2,b2[i]=(c+1)%2;
    c++;i--;
  }
  int pp=0,pp1=0;
  r(i,n)if(a1[i]!=b1[i])pp++;
  r(i,n)if(a1[i]!=b2[i])pp1++;
  if(!pp||!pp1){
    cout<<0<<endl;
    return 0;
  }
  int x1=0,y1=0,z1=0;
  r(i,n)if(a1[i])x1++;
  r(i,n)if(b1[i])y1++;
  r(i,n)if(b2[i])z1++;
  int p1=0,p2=0,c1=0,c2=0,k;
  if(x1==y1)for(int j=0;j<n-1;j++)
    if(a1[j]!=b1[j])
      for(int i=j;i<n;i++)
        if(a1[i]==b1[j]){swap(a1[i],a1[j]),p1+=i-j,c1++;break;}
  if(x1==z1)for(int j=0;j<n-1;j++)
    if(a2[j]!=b2[j])
      for(int i=j;i<n;i++)
        if(a2[i]==b2[j]){swap(a2[i],a2[j]),p2+=i-j,c2++;break;}
  if(c1&&c2)k=min(p1,p2);
  else if(c1)k=p1;
  else k=p2;
  cout<<k<<endl;
}

Measured memory_bytes: 3084
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF = ll(1e10)+1;

struct UnionFind
{
   vector<int> par;

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

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

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

   bool issame(int x, int y)
   {
      if (root(x) == root(y))
         return true;
      return false;
   }
};

void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<P> AB;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    AB.emplace_back(a, b);
    uf.merge(a, b);
  }
  vector<P> CD;
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    c--; d--;
    CD.emplace_back(c, d);
  }
  vector<int> score(n, -1);
  rep(i, n) score[uf.root(i)]++;
  rep(i, n) score[i] = score[uf.root(i)];
  rep(i, m) {
    int a = AB[i].first;
    int b = AB[i].second;
    if (uf.issame(a, b)) {
      score[a]--; score[b]--;
    }
  }
  rep(i, k) {
    int c = CD[i].first;
    int d = CD[i].second;
    if (uf.issame(c, d)) {
      score[c]--; score[d]--;
    }
  }
  rep(i, n) cout << score[i] << ' ';
  cout << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 3572
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

typedef unsigned long long lu;
const int mod = 1e9 + 7;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }

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

int Inv(int x) { return Pow(x, mod - 2); }

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

const int maxn = 600;
typedef pair<int, int> pii;

int n, N, d1, d2;
int c1[maxn][maxn], c2[maxn][maxn];
int sq[200001];

void Dfs(int x, int y, int D, int C[maxn][maxn]) {
  for (int dx = 0; dx * dx <= D; ++dx) {
    int dy = sq[D - dx * dx];
    if (dy == -1) continue;
    for (int sx = -1; sx <= 1; sx += 2) {
      for (int sy = -1; sy <= 1; sy += 2) {
        int x2 = x + dx * sx, y2 = y + dy * sy;
        if (x2 >= 0 && x2 < N && y2 >= 0 && y2 < N) {
          if (C[x2][y2] == -1) {
            C[x2][y2] = !C[x][y];
            Dfs(x2, y2, D, C);
          }
        }
      }
    }
  }
}

void Color(int D, int C[maxn][maxn]) {
  for (int x = 0; x < N; ++x) {
    for (int y = 0; y < N; ++y) {
      if (C[x][y] == -1) {
        C[x][y] = 0;
        Dfs(x, y, D, C);
      }
    }
  }
}

int main(void) {
  for (int i = 0; i <= 200000; ++i) {
    int j = (int)round(sqrt(i));
    if (j * j == i) {
      sq[i] = j;
    } else {
      sq[i] = -1;
    }
  }
  scanf("%d%d%d", &n, &d1, &d2);
  N = n * 2;
  FILLA(c1, -1);
  FILLA(c2, -1);
  Color(d1, c1);
  Color(d2, c2);

  vector<pii> p[4];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      p[c1[i][j] << 1 | c2[i][j]].push_back(pii(i, j));
    }
  }
  for (int i = 0; i < 4; ++i) {
    if (p[i].size() >= n * n) {
      for (int j = 0; j < n * n; ++j) {
        printf("%d %d\n", p[i][j].first, p[i][j].second);
      }
      return 0;
    }
  }

  throw;
}


Measured memory_bytes: 58100
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
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; }
typedef unsigned long ul;
typedef unsigned int ui;
const ul INF = 1LL<<60;
long N,Y,x,y,z;
// void rec(ui x,ui y,ui z){
//   if(x+y+z>N){
//     return;
//   }
//   if(x+y+z==N&&x*10000+y*5000+z*1000==Y){
//     OUT3(x,y,z);
//     exit(0);
//   }
//   rec(x+1,y,z);
//   rec(x,y+1,z);
//   rec(x,y,z+1);
// }

// inline void solve(){
//   IN2(N,Y);
//   Y/=1000;
//   x=Y/10;
//   Y-=x*10;
//   y=Y/5;
//   Y-=y*5;
//   z=Y;
//   while(x+y+z<N){
//     if(N-x-y-z>=9){
//       x-=1;
//       z+=10;
//     }else if(N-x-y-z>=4){
//       y-=1;
//       z+=5;
//     }
//   }
//   if(x+y+z==N)OUT3(x,y,z);
//   else OUT3(-1,-1,-1);
// }

inline void solve(){
  IN2(N,Y);
  REP(x,N+1)REP(y,N+1){
    z=N-x-y;
    if(z<0)break;
    if(10000*x+5000*y+1000*z==Y){
      OUT3(x,y,z);
      return;
    }
  }
  OUT3(-1,-1,-1);
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
import collections
import math

n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = collections.Counter(prime_factorize(n))

res = 0

for i in a.items():
    if i[1] > 3:
        x = 2
        y = 3
        while True:
            x += 1
            y = y + x
            if y > i[1]:
                res += x - 1
                break
    elif i[1] == 3:
        res += 2
    else:
        res += 1

print(res)    




Measured memory_bytes: 9484
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;


int compare_long(const void *a, const void *b) {
	return *(long long*)b - *(long long*)a;
}

int main()
{
    long long N;
	cin >> N;
	
	// f(x);
	
	long long confort[200001];
	
	long long sum = 0;
	for(long long k = 1; k <= N; k++) {
		
		cin >> confort[k];
	}
/*
	for(int i = 1; i <= N; i++) {
		for(int j = i; j <= N; j++) {
			if(confort[i] < confort[j]) {
				// 降順
				long long temp = confort[i];
				confort[i] = confort[j];
				confort[j] = temp;
			}
		}
	}
*/
	qsort(confort + 1, N,sizeof(long long), compare_long); 
	
	sum = confort[1];
	int i;
	for(i = 2; i <= N / 2; i++) {
		sum += confort[i] * 2;
	}
	if(N % 2 != 0) {
		sum += confort[i];
	}
	
	
	printf("%lld\n", sum);
	
    return 0;
}

Measured memory_bytes: 6392
//       ----------------- |\S/|\E/|\C/|\O/|\N/|\D/|\T/|\O/|\N/|\O/|\N/|\E/| ------------------
 #include<bits/stdc++.h>
using namespace std;
#define int long long int
#define I_L_Z_D ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
const int N = 1e5 + 8;
int dp[N];

int32_t main(){
I_L_Z_D;
	int n , k;	
	cin >> n >> k;
	int a[n + 1];
	for(int i = 0 ; i < n ;i++) cin >> a[i];
	fill(dp,dp + N , 1e9 + 2);
	 dp[0] = 0;
	for(int i = 0 ; i < n ;i++){
	   for(int j = i + 1 ; j <= i +  k ; j++)	
		if(j < n)
		dp[j] = min(dp[j]  , dp[i] + abs(a[i] - a[j]));
	}
	cout << dp[n - 1] << " ";
return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
  
int F[105][105];
int xg,yg;
  
  
void DFS(int Y,int X,int c){
  if(F[Y][X] != c){
    return;
  }
  
  F[Y][X] = -2000;
  DFS(Y-1,X  ,c);
  DFS(Y  ,X+1,c);
  DFS(Y+1,X  ,c);
  DFS(Y  ,X-1,c);
}
  
  
int main(){
  int w,h,xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;

      
    cin >> xs >> ys >> xg >> yg >> n;
    int c[n],d[n],x[n],y[n],ca;
    for(int i=0;i<n;i++){
      cin >> c[i] >> d[i] >> x[i] >> y[i];
    }
    for(int i=0;i<n;i++){
      if(c[i] == 0){
        ca = 1000;
        break;
      }else if(i == n-1){
        ca = 1000;
      }
    }
    for(int i=0; i<102; i++){
          for(int j=0; j<102; j++){
            F[i][j]=ca;
          }
    }
    for(int i=0;i<n;i++){
      if(d[i] == 0){
        for(int j=0;j<4;j++){
          F[x[i]+j][y[i]] = c[i];
          F[x[i]+j][y[i]+1] = c[i];
        }
      } else {
        for(int j=0;j<4;j++){
          F[x[i]][y[i]+j] = c[i];
          F[x[i]+1][y[i]+j] = c[i];
        }
      }
    }
 
  DFS(xs,ys,F[xs][ys]);
  
  if(F[xg][yg] == -2000){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3732
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    cout << min(A, B) + min(C, D) << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

constexpr int limit = 1e5;
constexpr int climit = 30;

int channel[climit+1][limit+1];
int all[limit+1];

int main(){
  int n, cs; cin >> n >> cs;
  int s[n+1], t[n+1], c[n+1];
  for(int i=1; i<=n; i++){
    cin >> s[i] >> t[i] >> c[i];
    channel[c[i]][s[i]] += 1;
    channel[c[i]][t[i]] += -1;
  }
 
  for(int i=1; i<=cs; i++){
    for(int j=1; j<=limit; j++){
      channel[i][j] += channel[i][j-1];
    }
  }
  
  for(int i=1; i<=n; i++){
    channel[c[i]][s[i]-1] = 1;
  }

  int ans = 0;
  for(int i=1; i<=cs; i++){
    for(int j=1; j<=limit; j++){
      all[j] += channel[i][j];
      ans = max(all[j], ans);
    }
  }

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

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

int main()
{
    int n, k, a[100000];

    while( cin >> n >> k )
    {
        if( n == 0 && k == 0 )
            break;
            
        for( int i = 0; i < n; i++ )
            cin >> a[i];
        
        int max = 0;
        for( int i = 0; i <= n - k; i++ )
        {
            int sum = 0;
            for( int j = i; j < i + k; j++ )
                sum += a[j];
            if( max < sum )
                max = sum;
        }

        cout << max << endl;
    }

    return 0;
}


Measured memory_bytes: 3400
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int x, y;
  cin >> x >> y;
  int L = s.size();
  bool f = true;
  string t;
  for (int i = 0; i < L; i++){
    if (s[i] == 'T'){
      if (!f){
        t += 'T';
      }
      f = false;
    } else {
      if (f){
        x--;
      } else {
        t += 'F';
      }
    }
  }
  vector<int> Y(1, 0);
  vector<int> X(0);
  int N = t.size();
  int d = 0;
  for (int i = 0; i < N; i++){
    if (t[i] == 'F'){
      if (d == 0){
        Y.back()++;
      } else {
        X.back()++;
      }
    } else {
      if (d == 0){
        X.push_back(0);
        d = 1;
      } else {
        Y.push_back(0);
        d = 0;
      }
    }
  }
  if (Y.back() == 0){
    Y.pop_back();
  }
  if (!X.empty()){
    if (X.back() == 0){
      X.pop_back();
    }
  }
  int ycnt = Y.size();
  vector<vector<bool>> dp(ycnt + 1, vector<bool>(L * 2 + 1, false));
  dp[0][L] = true;
  for (int i = 0; i < ycnt; i++){
    for (int j = 0; j <= L * 2; j++){
      if (dp[i][j]){
        dp[i + 1][j + Y[i]] = true;
        dp[i + 1][j - Y[i]] = true;
      }
    }
  }
  int xcnt = X.size();
  vector<vector<bool>> dp2(xcnt + 1, vector<bool>(L * 3 + 1, false));
  dp2[0][L * 2] = true;
  for (int i = 0; i < xcnt; i++){
    for (int j = 0; j <= L * 3; j++){
      if (dp2[i][j]){
        dp2[i + 1][j + X[i]] = true;
        dp2[i + 1][j - X[i]] = true;
      }
    }
  }
  if (dp[ycnt][y + L] && dp2[xcnt][x + L * 2]){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 22916