akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val a = IntArray(n)
    var sum: Long = 0
    var cnt = 0
    var zero = 0
    for (i in 0 until n) {
        a[i] = scanner.nextInt()
        if (a[i] < 0) {
            cnt++
            a[i] = Math.abs(a[i])
        } else if (a[i] == 0) zero++
        sum += a[i]
    }
    println(
        if (cnt % 2 == 0) sum
        else if (cnt % 2 == 1 && zero > 0) sum
        else sum - 2 * a.min()!!
    )
}


Measured memory_bytes: 52916
#include <stdio.h>

int main(void)
{
	int x[2], y[2], z[2], w[2];
	int i, j, n;
	
	while (scanf("%d", &n), n != 0){
		for (i = 0; i < n; i++){
			for (j = 0; j < 2; j++){
				scanf("%d %d %d %d", &x[j], &y[j], &z[j], &w[j]);
			}
			
			printf("%d %d %d %d\n"
			, x[0] * x[1] - y[0] * y[1] - z[0] * z[1] - w[0] * w[1]
			, x[0] * y[1] + y[0] * x[1] + z[0] * w[1] - w[0] * z[1]
			, x[0] * z[1] - y[0] * w[1] + z[0] * x[1] + w[0] * y[1]
			, x[0] * w[1] + y[0] * z[1] - z[0] * y[1] + w[0] * x[1]);
		}
	}
	
	return (0);
}

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

int T, card[16];

bool is_same_number(int a, int b, int c) {
  return a==b && b==c;
}
bool is_sequence(int a, int b, int c) {
  return (a+2 == c && b+1 == c);
}
bool is_good_set(int a, int b, int c) {
  return is_same_number(a, b, c) || is_sequence(a, b, c);
}
bool is_all_good_set () {
  return is_good_set(card[0],card[1],card[2])
    && is_good_set(card[3],card[4],card[5])
    && is_good_set(card[6],card[7],card[8]);
}
int win() {
  // Sort the card
  sort(card, card+9);
  do {
    if (is_all_good_set())
      return 1;
  } while (next_permutation(card, card+9));
  return 0;
}

int main() {
  cin >> T;
  for (int t=0; t<T; ++t) {
    for (int i=0; i<9; ++i) {
      cin >> card[i];
    }
    string color;
    for (int i=0; i<9; ++i) {
      cin >> color;
      if (color == "G") card[i] += 10;
      else if (color == "B") card[i] += 20;
    }
    //cout << sort(card, card+9) << endl;
    cout << win() << endl;   
  }
}

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

int main() {
  int N;
  cin >> N;
  int a[100001]={};
  int max=0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    a[x]++;
  }
  for(int i=1;i<99999;i++){
    if(a[i-1]+a[i]+a[i+1]>max)max=a[i-1]+a[i]+a[i+1];
  }
  cout << max;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

#include <bits/stdc++.h>
#define rep(i,a,n) for(ll i = a;i < n;i++)
typedef long long ll;
using namespace std;

struct unionfind {
    vector<int> par;
    vector<int> sizes;

    unionfind(int n) : par(n),sizes(n,1){
        rep(i,0,n) par[i] = i;
    }

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

    void unite(int x,int y){
        x = root(x);
        y = root(y);

        if(x == y) return;

        if(sizes[x] < sizes[y] ) swap(x,y);

        par[y] = x;
        sizes[x] += sizes[y];
        sizes[y] = 0;

        return;
    }

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

    int size(int x){
        return sizes[root(x)];
    }
};

int main(){
    ll n,m;
    cin >> n >> m;
    
    ll a[n] = {};
    ll memo[n] = {};
    unionfind uf(n);
    ll ans = 0;

    rep(i,0,n){
        cin >> a[i];
        memo[a[i]-1] = i;
    }

    rep(i,0,m){
        ll a,b;
        cin >> a >> b;
        a--;b--;

        if(!uf.same(a,b)) uf.unite(a,b);
    }

    rep(i,0,n){
        if(uf.same(memo[i],i)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define maxn 1000010
#define maxm 1000010
#define ls x << 1
#define rs x << 1 | 1
#define inf 10000000000
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
#define int long long
#define XRZ 212370440130137957
#define debug() puts("XRZ TXDY");
#define mem(i, x) memset(i, x, sizeof(i));
#define Next(i, u) for(register int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(register int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
int dx[10] = {1, -1, 0, 0};
int dy[10] = {0, 0, 1, -1};
using namespace std;
inline int read() {
    register int x = 0, f = 1; register char c = getchar();
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
} char s = '0'; int ans;
signed main() {
	while(s >= '0' && s <= '9') { scanf("%c", &s);
		if(s < '0' || s > '9') break;
		ans = (ans + s - '0') % 9;// printf("%d %c\n", ans);
	} if(ans == 0) puts("Yes"); else puts("No");
	return 0;
}

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

int main()
{

    long long int A = 0, B = 0, C = 0, K = 0;
    long long int sum = 0;

    scanf("%lld%lld%lld%lld", &A, &B, &C, &K);

    if(K > A){
        sum += A;
        K = K - A;
        if(K > B){
            K = K - B;
            sum -= K;
            printf("%lld\n", sum);
        }
        else{
            printf("%lld\n", sum);
        }
    }
    else{
        printf("%lld\n", K);
    }



    return 0;
}



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

int main() {
  int n;
  string ans = "APPROVED";
  cin >> n;
  rep(i, n) {
    int a;
    cin >> a;
    if (a % 2 == 0) {
      if (a % 3 != 0 && a % 5 != 0) {
        ans = "DENIED";
      }
    }
  }
  cout << ans << endl;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int h,w,a,b;
	cin >> h >> w >> a >>b;
	cout << (h%a) * w + (w%b) * h - (h%a) * (w%b) << endl;

	return 0;
}



Measured memory_bytes: 3076
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	int h,w;
	scanf("%i%i",&h,&w);
	char s[h+1][w+1];
	for(int i=0;i<h;i++)
	{
		scanf("%s",&s[i]);
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(s[i][j]=='#')
			{
				if(j!=w && s[i][j]!=s[i][j+1] && i!=h && s[i][j]!=s[i+1][j] && j!=1 && s[i][j]!=s[i][j-1] && i!=1 && s[i][j]!=s[i-1][j])
				{
					printf("No");
					return 0;
				}
			}
		}
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, j, n;
  int data[11][11];

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

    for(i=0; i<11; i++){
      for(j=0; j<11; j++)
	data[i][j] = 0;
    }    

    for(i=0; i<n; i++){
      for(j=0; j<n; j++)
	scanf("%d", &data[i][j]);
    }

    for(i=0; i<n; i++){
      for(j=0; j<n; j++)
	data[i][n] += data[i][j];
    }
    for(i=0; i<n; i++){
      for(j=0; j<n; j++)
	data[n][i] += data[j][i];
    }
    for(i=0; i<n; i++)
      data[n][n] += data[n][i];

    for(i=0; i<=n; i++){
      for(j=0; j<=n; j++)
	printf("%5d", data[i][j]);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
struct UnionFind {
	vector<int> par, s;
	UnionFind(int N) : par(N), s(N, 1) { rep(i, 0, N)par[i] = i; }
	int root(int x) { return par[x] == x ? x : par[x] = root(par[x]); }
	void unite(int x, int y) { x = root(x), y = root(y); if (x == y)return; if (s[x] < s[y])swap(x, y); s[x] += s[y]; par[y] = x; }
	bool same(int x, int y) { return root(x) == root(y); }
	int size(int x) { return s[root(x)]; }
	map<int, int> cnt() { map<int, int> cnt; rep2(v, par)cnt[root(v)]++; return cnt; }
};
int main()
{
	ll n, m;
	cin >> n >> m;
	vector<pair<int, int>> br(m);
	rep(i, 0, m)cin >> br[i].first >> br[i].second, br[i].first--, br[i].second--;
	UnionFind uf(n);
	reverse(all(br));
	vector<ll> A;
	ll e_cnt = n * (n - 1) / 2;
	for (const auto& p : br)
	{
		A.push_back(e_cnt);
		if (!uf.same(p.first, p.second))
		{
			e_cnt -= uf.size(p.first) * uf.size(p.second);
			uf.unite(p.first, p.second);
		}
	}
	reverse(all(A));
	rep2(v, A)printf("%lld\n", v);
	return 0;
}

Measured memory_bytes: 5860
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;

using P = pair<char,int>;
struct union_find{
    vector<int> par;
    union_find(int n){
        par = vector<int>(n);
        init(n);
    }
    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    int find(int x){
        if(par[x]==x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y){//y???????????????
        x = find(x);
        y = find(y);
        par[x]=y;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

int main(){
    int N,Q;
    while(cin>>N>>Q,N){
        bool isMarked[100000];
        int parent[100000];
        fill(isMarked,isMarked+100000,false);
        fill(parent,parent+100000,5000000);
        parent[0]=0;
        for(int i=1;i<N;i++){
            int p;
            cin>>p; p--;
            parent[i]=p;
        }
        vector<P> V;
        isMarked[0]=true;
        for(int i=0;i<Q;i++){
            char C;
            int v;
            cin>>C>>v; v--;
            if(C=='Q'){
                V.emplace_back(C,v);
            }else if(!isMarked[v]){
                isMarked[v]=true;
                V.emplace_back(C,v);
            }
        }
        union_find UF(N);
        for(int i=1;i<N;i++){
            if(!isMarked[i]) UF.unite(i,parent[i]);
        }

        reverse(V.begin(), V.end());
        int64_t ans = 0;
        for(auto p:V){
            char C; int v;
            tie(C,v)=p;
            if(C=='Q'){
                ans+=UF.find(v)+1;
            }else{
                if(v==0) cout<<'A'<<endl;
                isMarked[v]=false;
                UF.unite(v,parent[v]);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<long long, long long>> ans(n);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        ans[i] = make_pair(a, b);
    }
    sort(ans.begin(), ans.end());
    long long cost = 0, cnt = 0;
    for(int i = 0; i < n; i++){
        if(ans[i].second > m - cnt){
            cost += (m - cnt) * ans[i].first;
            cout << cost << endl;
            return 0;
        }
        else{
            cost += ans[i].second * ans[i].first;
            cnt += ans[i].second;
        }
    }
    cout << cost << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

ll dp[101][21];
int a[101];

int main()
{
	memset (dp, 0LL, sizeof (dp ) );
	memset (a, 0, sizeof (a ) );

	int n;
	cin >> n;
	rep (i, n ){
		cin >> a[i];
	} // end rep

	dp[0][a[0]] = 1LL;
	for (int i = 1; i < n - 1; i++ ){
		for (int j = 0; j <= 20; j++ ){
			if (dp[i-1][j] ){
				if ( j + a[i] <= 20 ){
					dp[i][j + a[i]] += dp[i-1][j];
				} // end if
				if ( j - a[i] >= 0 ){
					dp[i][j - a[i]] += dp[i-1][j];
				} // end if
			} // end if
		} // end for
	} // end for

	cout << dp[n-2][a[n-1]] << endl;

	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){
    return (a%b+b)%b;
}
ll gcd(ll a, ll b){
    return b ? gcd(b, a%b) : a;
}
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}
void Yes(){
    cout << "Yes" << endl;
}
void No(){
    cout << "No" << endl;
}
void Judge(bool b){
    b ? Yes() : No();
}
void YES(){
    cout << "YES" << endl;
}
void NO(){
    cout << "NO" << endl;
}
void JUDGE(bool b){
    b ? YES() : NO();
}
ll powmod(ll b, ll e){
    ll r = 1; while(e > 0) {if(e&1) r = (r%MOD)*(b%MOD)%MOD; b = (b%MOD)*(b%MOD)%MOD; e >>= 1;} return r;
}
double distance(ll x1, ll y1, ll x2, ll y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

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;
}
template<typename T>
void ppp(T n){
    cout << n << endl;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for(int i = 0; i < len; ++i) {
        s << v[i]; if(i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa {
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    }
} fastio;

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> s(n+2), t(n+2);
    partial_sum(a.begin(), a.end(), s.begin()+1,
                [](int x, int y){return max(x, y);});
    partial_sum(a.rbegin(), a.rend(), t.rbegin()+1,
                [](int x, int y){return max(x, y);});
    rep(i, n){
        ppp(max(s[i], t[i+2]));
    }


    return 0;
}


Measured memory_bytes: 3968
use proconio::input;

fn gcd(m: usize, n: usize) -> usize {
    if m < n {
        gcd(n, m)
    } else {
        let r = m % n;
        if r == 0 {
            n
        } else {
            gcd(n, r)
        }
    }
}

fn main() {
    input! {
        k: usize,
    };
    let mut ans = 0;
    for a in 1..=k {
        for b in 1..=k {
            let x = gcd(a, b);
            for c in 1..=k {
                ans += gcd(x, c);
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> p;
  ll ans=0;
  
  rep(i,n){
    int a,b;
    cin >> a >> b;
    p.emplace_back(b,a);  
  }
  sort(p.begin(),p.end());
  rep(i,n){
    ans+=p[i].second;
    if(ans > p[i].first){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
      
      
  
  
  
  


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    int X = inputValue();
    int Y = inputValue();

    int ans = 0;
    switch(X){
        case 1:
            ans += 300000;
            break;
        case 2:
            ans += 200000;
            break;
        case 3:
            ans += 100000;
            break;
    }
    switch(Y){
        case 1:
            ans += 300000;
            break;
        case 2:
            ans += 200000;
            break;
        case 3:
            ans += 100000;
            break;
    }
    if(X==1 && Y==1){
        ans += 400000;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


int n,m;

int32_t main()
{
	IOS;
	cin>>n>>m;
	m*=4;
	vector<int>v(n);
	int  sum=0;
	for(int i=0;i<n;i++){
		cin>>v[i];
		
		sum+=v[i];
	}
	if(sum%m==0)
		sum/=m;
	else{
		sum=sum/m+1; 
	}
	int cou=0;
	for(int i=0;i<n;i++){
		if(v[i]>=sum)
			cou++;
	}
	m= m/4;
	if(cou>=m)
		cout<<"Yes"<<endl;
	
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;cin>>N>>K;
  vector<int>A(K);
  for(int i=0;i<K;i++)cin>>A[i];
  for(int i=N;;i++){
    string S=to_string(i);
    bool b=false;
    for(int j=0;j<S.size();j++){
      for(int k:A)
        if(S.at(j)=='0'+k){b=true;break;}
      if(b)break;
      if(j==S.size()-1){cout<<i<<endl;return 0;}
    }
  }
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

struct Corr{
    int pos;
    int len;
};

vi ans(101010,-1);
vector<vector<Corr> > v(101010);

int dfs(int pos){
    for(int i=0;i<v[pos].size();i++){
        int next=v[pos][i].pos;
        int len=v[pos][i].len;
        if(ans[next]!=-1)continue;
        if(len%2==0){
            ans[next]=ans[pos];
        } else {
            ans[next]=1-ans[pos];
        }
        dfs(next);
    }
    return 0;
}

int main() {
    
    int n;
    cin>>n;
    rep(i,n-1){
        int U,V,W;
        cin>>U>>V>>W;
        U--;V--;
        Corr c1={U,W};
        Corr c2={V,W};
        v[U].pb(c2);
        v[V].pb(c1);
    }
    ans[0]=0;
    dfs(0);
    rep(i,n){
        cout<<ans[i]<<endl;
    }

}



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

int main()
{
	int a, b;
	cin >> a >> b;
	if (a >= 13) {
		cout << b << endl;
	}
	else if (a >= 6) {
		cout << b / 2 << endl;
	}
	else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
import sys
from itertools import permutations


def input():
    return sys.stdin.readline().strip()


def main():
    N, M, R = map(int, input().split())

    def warshall_floyd(d):
        # d[i][j]: iからjへの最短距離
        for k in range(N):
            for i in range(N):
                for j in range(N):
                    tmp = d[i][k] + d[k][j]
                    if d[i][j] > tmp:
                        d[i][j] = tmp
        return d

    r = list(map(int, input().split()))
    d = [[float("inf")] * N for i in range(N)]
    for i in range(M):
        x, y, z = map(int, input().split())
        d[x - 1][y - 1] = z
        d[y - 1][x - 1] = z
    for i in range(N):
        d[i][i] = 0  # 自身のところに行くコストは０
    D = warshall_floyd(d)
    P = list(permutations(r))
    cost = float("inf")
    for p in P:
        c = 0
        for i in range(R - 1):
            c += D[p[i] - 1][p[i + 1] - 1]
        if c < cost:
            cost = c
    print(cost)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9556
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <complex>
using namespace std;
const double EPS = 1e-8;
typedef complex<double> P;
#define X real()
#define Y imag()
double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}

int main(){
    while(1){
        double d;
        cin >> d;
        if(d==0) break;

        double px,py,vx,vy;
        cin >> px >> py >> vx >> vy;
        P p(px,py), v(vx,vy);
        double ans = 1e9;
        if(abs(cross(p, p+v)) < EPS){
            if(dot(p, v) > 0){
                ans = 2-abs(p);
            }else{
                ans = abs(p);
            }
        }
        if(ans > d){
            cout << "impossible" << endl;
        }else{
            cout << fixed << setprecision(10);
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3284
#include <stdio.h>

int main()
{
	int a, b,c;
	scanf("%d %d %d", &a, &b,&c);

	if (c > b) {
	    if(b > a){
	    	printf("Yes\n");
	}else printf("No\n");
	}else printf("No\n");
	
    return 0;
}



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

int main(){
    vector<pair<ll,ll>> V;
    ll N,M; cin>>N>>M;

    for(int i=0;i<N;i++){
        int a;  cin>>a;
        V.push_back({a,1}); //ランレングス圧縮
    }
    for(int i=0;i<M;i++){
        int b,c;    cin>>b>>c;
        V.push_back({c,b}); //ランレングス圧縮
    }
    sort(V.begin(),V.end(),greater<pair<ll,ll>>()); //greaterは降順ソート

    ll count=N;
    ll ans=0;
    for(auto itr=V.begin();itr!=V.end();itr++){
        ans=ans+itr->first*min(itr->second,count);
        count=count-itr->second;
        if(count<=0)break;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N, C;
  cin>>N>>C;
  int D[C][C], c;
  REP(i, C){
    REP(j, C) cin>>D[i][j];
  }
  int col[3][C]; //色の個数[(i+j)%3][もとのcolor]
  int cost[3][C]; //違和感[(i+j)%3][変更後のカラー]
  REP(i, 3){
    REP(j, C){
      col[i][j]=0;
      cost[i][j]=0;
    }
  }
  REP(i, N){
    REP(j, N){
      cin>>c;
      --c;
      ++col[(i+j)%3][c];
    }
  }
  REP(i, 3){
    REP(j, C){
      REP(k, C){
        cost[i][j] += col[i][k] * D[k][j];
      }
    }
  }

  int ans=2000000000;
  REP(i, C) REP(j, C) REP(k, C){
    if(i == j ||j == k ||k == i) continue;
    ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
  }
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

const int inf = 1e9 + 10;

struct UF {
	vi data;
	void init(int n)
	{
		data.resize(n);
		fill(all(data), -1);
	}
	int root(int x)
	{
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	void unite(int x, int y)
	{
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (size(x) < size(y)) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
	int size(int x)
	{
		x = root(x);
		return -data[x];
	}
	bool is_root(int x)
	{
		return x == root(x);
	}
};

UF uf;
int N, M;
vector<int> G[100010];

signed main()
{
	cin >> N >> M;
	uf.init(N);

	rep(i, M) {
		int a, b; cin >> a >> b;
		--a, --b;
		if (a < b) swap(a, b);
		G[a].PB(b);
	}

	int ans = N - 1;

	rep(u, N - 1) {
		bool f = true;
		
		for (int v : G[u + 1]) {
			if (uf.same(u, v) and f) {
				f = false;
			}
		}

		if (f) {
			uf.unite(u, u + 1);
			ans--;
		}
	}

	cout << ans << endl;
}


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

using namespace std;

int main (){
  int n,m;
  cin >> n >> m;
  vector<int> targets;
  
  int i=0;
  for(;i < m;i++){
    int buf;
    cin >> buf;
    targets.push_back(buf);
  }
  sort(targets.begin(), targets.end());
  int sum = 0;
  vector<int> diffs;
  int buf = 0;
  for(i=0;i<m;i++){
    if(i==0){
      buf = targets[i];
      continue;
    }
    int d = targets[i] - buf;
    sum += d;
    diffs.push_back(d);
    buf = targets[i];
  }
  sort(diffs.begin(), diffs.end());
  reverse(diffs.begin(),diffs.end());
  for(i=0;i<n-1 && i < m-1;i++){
    sum -= diffs[i];
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

    public static void main(String[] args)  {
        //input
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] t = new int[n];
        int[] f = new int[n];

        for (int i = 0; i < m; i++) {
            int v = sc.nextInt() - 1;
            String s = sc.next();
            if (s.contains("AC")) {
                t[v] = 1;
            } else if (t[v] != 1){
                f[v] += 1;
            }
        }

        //解析
        long ct_t = 0;
        long ct_f = 0;
        for (int i = 0; i < n; i++) {
            ct_t += (t[i] == 0)? 0 : 1;
            ct_f += (t[i] == 0)? 0 : f[i];
        }

        System.out.println(ct_t + " " + ct_f);
    }
}

Measured memory_bytes: 63572
table = {}

queue = [[[*'0'..'7'], 0]]
until queue.empty?
  current, num = queue.shift

  next if table[current]
  table[current] = num

  zero_pos = current.index('0')

  dists = [zero_pos - 4, zero_pos + 4]
  dists << zero_pos - 1 if zero_pos != 4
  dists << zero_pos + 1 if zero_pos != 3
  dists.each do |pos|
    next unless pos.between?(0, 7)

    current2 = current.dup
    current2[zero_pos], current2[pos] = current2[pos], current2[zero_pos]
    queue << [current2, num + 1]
  end
end

while line = gets
  puts table[line.split(' ')]
end

Measured memory_bytes: 11020
#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() {
  int x, y;
  cin >> x >> y;
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  vector<int> d;
  rep(i, x) d.push_back(p[i]);
  rep(i, y) d.push_back(q[i]);
  rep(i, c) d.push_back(r[i]);
  sort(d.rbegin(), d.rend());
  ll ans = 0;
  rep(i, x + y) ans += d[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define  X first
#define  Y second

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;

const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 3e5+10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 998244353;

int V[maxN];
int W[maxN];
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	for(int i=0;i<=x;i++)
	{
		if(2*i + 4*(x-i) == y)
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3688
import heapq
N, M = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for i in range(M):
  mm = heapq.heappop(a)
  heapq.heappush(a, (-mm//2) * (-1))
  
print(-sum(a))



Measured memory_bytes: 14380
//#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	string s[101];
	int t[101];
	string X;
	scan(N);
	rep(i,N){
		scan(s[i]>>t[i]);
	}
	scan(X);
	int flag=0;
	int ans=0;
	rep(i,N){
		if(flag) ans+=t[i];
		if(X==s[i]) flag=1;
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())
k = int(input())
count = 0
while count<k and a>=b:
    b = 2*b
    count +=1
while count<k and b>=c:
    c = c*2
    count +=1
# print(a,b,c,count)
if a<b and  b<c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);

double W,H;
double x,y;

signed main()
{

    cin >> W >> H >> x >> y;

    if(W/2==x&&H/2==y)printf("%f 1\n",(W*H)/2.0);

    else printf("%f 0\n",(W*H)/2.0);


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n, W, H;
    cin >> n >> W >> H;
    vector<int> x(n), y(n), w(n);
    rep(i, n) cin >> x[i] >> y[i] >> w[i];

    vector<int> X(W+2,0), Y(H+2,0);
    rep(i, n){
        int l = max(x[i]-w[i], 0);
        int r = min(x[i]+w[i], W);
        // cout << l << " " << r << endl;
        X[l]++; X[r]--;
        l = max(y[i]-w[i], 0);
        r = min(y[i]+w[i], H);
        // cout << l << " " << r << endl;

        Y[l]++; Y[r]--;
    }
    rep(i, W) X[i+1] += X[i];
    rep(i, H) Y[i+1] += Y[i];

    bool ans = 0;
    rep(i, W)if(X[i] == 0){
        ans = 1;
        break;
    }
    if(ans)rep(i, H)if(Y[i] == 0){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;


}


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

using namespace std;

#define mod 1000000007
#define inf 1e18


int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  int a, b;
  cin >> a >> b;
  if (b == 0 || b % 2 == 1) {
    cout << "No" << endl;
  } else if (b >= 2 * a && b <= 4 * a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll N;
    cin >> N;
    if(!cin) return;
    vector<ll> A, X(N+1, 0);
    for (int i = 0; i < N; ++i) {
        ll ta;
        cin >> ta;
        A.push_back(ta);
        X[ta] = ta;
        if(X[ta-1] != 0){
            X[ta-1] = ta;
        }
    } // end i
    ll ans = INF;
    for (int i = 1; i <= N; ++i) {
        ans = min(ans, N - [&](){
            int k = i;
            while(X[k] != k){ X[k] = k; k++; }
            return k - i + 1;
        }() );
    } // end i
    cout << ans << endl;


}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    cerr << "DEBUG MODE" << endl;
    string test_cases = "test.txt";
    auto fs = fstream(test_cases, fstream::in);
    while(fs) {
        solve(fs);
    }
#else
    solve(cin);
#endif
    return 0;
}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
 
#define int long long int
#define pb push_back
#define mp make_pair
#define loop(i,x,n) for(int i=x;i<=n;i++)
#define rloop(i,x,n) for(int i=x;i>=n;i--)
#define ff first
#define ss second
#define N4RUTO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
typedef tree<int, null_type, less<int>, rb_tree_tag,  
tree_order_statistics_node_update>
ordered_set;
 
int32_t main(){
    N4RUTO;
    int h,n;
    cin>>h>>n;
    int ans = 0;
    loop(i,0,n-1) {
        int x;
        cin>>x;
        ans+=x;
    }
    if(ans>=h) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0;
            int xmax = 0;
            int N = int.Parse(Console.ReadLine());
            String S = Console.ReadLine();
            for(int i = 0; i < N; i++)
            {
                if (S[i] == 'I')
                {
                    x++;
                    if (x > xmax)
                    {
                        xmax = x;
                    }
                }
                else
                {
                    x--;
                }
            }
            Console.WriteLine(xmax);
        }
    }
}


Measured memory_bytes: 13140
import sys
from collections import Counter

N = int(sys.stdin.readline().strip())
A = map(int, sys.stdin.readline().strip().split())
counter = Counter(A)

even_count = 0
for (n, count) in counter.items():
    if count % 2 == 1:
        N -= count // 2 * 2
        counter[n] = 1
    else:
        N -= count - 2
        counter[n] = 2
        even_count += 1

print(N - (even_count + 1) // 2 * 2 )

Measured memory_bytes: 59692
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << "   ";
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int inf = 1LL << 60;
const int N = 3000 + 10;
int dp[2][N][N]; // 0 try to max x-y  and 1 try to min x-y   0 : x   ___  1 : y
int a[N];
int n;

int solve(int l, int r, int p)
{
    if(l == r){
        dp[p][l][r] = (p==0?1:-1) * a[l];
        return dp[p][l][r];
    }
    if(dp[p][l][r] != inf){
        return dp[p][l][r];
    }

    if(p == 0){
        dp[0][l][r] = max( solve(l+1,r,1) + a[l] , solve(l,r-1,1) + a[r]);
    }
    else{
        dp[1][l][r] = min( solve(l+1,r,0) - a[l] , solve(l,r-1,0) - a[r]);
    }
    return dp[p][l][r];
}

int32_t SALI()
{
    for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) dp[0][i][j] = dp[1][i][j] = inf;
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cout << solve(1,n,0);

}


/**< WRITEN BY ALI ADELKHAH */



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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    rep(i, n) {
        int h; cin >> h;
        if (h >= k) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm> // sort
#include <map>       // pair
#include <vector>
using namespace std;

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


const int INF = 100100100;
const int MOD = (int)1e9 +7;
const double EPS = 1e-9; 

typedef long long int ll;

//char in[120];
//ex. pair
//pair<pair<string,int>,int> p[110];

int main(){
    int n;cin>>n;
    REP(n,1000){
        if( (i%111) !=0) continue;
        else{
            COUT(i);
            return 0;
        }
    }
    
    //FOR(p.size()){
    //   cout << p[i].first << " " << p[i].second<<endl;
    //}

    return 0;    
}

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

int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2]){
    cout << "No";
    return 0;
  }
  if(s[0] == s[2] && s[1] == s[3]){
    cout << "Yes";
    return 0;
  }
  if(s[0] == s[3] && s[2] == s[1]){
    cout << "Yes";
    return 0;
  }
  if(s[0] == s[1] && s[2] == s[3]){
    cout << "Yes";
    return 0;
  }
  cout << "No";
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
)

func main() {

	var N int
	fmt.Scanf("%d", &N)

	S := make([]string, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%s", &S[i])
	}

	m := make(map[string]bool)
	uniq := []string{}

	for _, ele := range S {
		if !m[ele] {
			m[ele] = true
			uniq = append(uniq, ele)
		}
	}

	fmt.Println(len(uniq))
}


Measured memory_bytes: 35844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h,n;cin>>h>>n;
    vector<ll> a(n),b(n);rep(i,n)cin>>a[i]>>b[i];
    vector<ll> dp(h+1,INF);//dp[i]:i減らす魔力
    dp[0]=0;
    for(int i=1; i<=h; i++){
        for(int j=0; j<n; j++){
            dp[i]=min(dp[i],dp[max(0LL,i-a[j])]+b[j]);
        }
    }
    cout<<dp[h];

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define int long long
using namespace std;
const int N_MAX=100000;
int N;
vector<tuple<int,int,int>> happy;
int memo[N_MAX+1][4];
int dfs(int i,int act){
    if(i==N) return 0;
    if(memo[i][act]>0) return memo[i][act];
    int a[3];
    tie(a[0],a[1],a[2])=happy[i];
    int ret=0;
    REP(j,3){
        if(act==j) continue;
        ret=max(ret,dfs(i+1,j)+a[j]);
    }
    return memo[i][act]=ret;
}
signed main(){
    cin>>N;
    REP(i,N){
        int a,b,c;
        cin>>a>>b>>c;
        happy.emplace_back(a,b,c);
    }
    cout<<dfs(0,4)<<endl;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Poor
            var line = ReadLine();

            var dic = new Dictionary<int, int>();

            foreach(var n in line)
            {
                if (dic.ContainsKey(n))
                {
                    dic[n]++;
                }
                else
                {
                    dic.Add(n, 1);
                }
            }

            bool isPoor = false;

            foreach(var d in dic)
            {
                if (d.Value == 2)
                {
                    isPoor = true;
                    break;
                }
            }

            if (isPoor)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
#define int ll
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define vi vector<int>
#define pii pair<int,int>
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define MAX 52
#define initialize(arr,elem) memset(arr,elem,sizeof(arr))
#define sz size
const int MOD = 1e9+7;

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int graph[MAX][MAX], n,k, identity[MAX][MAX];

void rand_shuff(vi &arr){
	random_device rd;
	mt19937 g(rd());
	shuffle(all(arr),g);
}
void multiply(int a[MAX][MAX], int b[MAX][MAX], int c[MAX][MAX]){
	For(i,0,n){
		For(j,0,n) c[i][j] = 0;
	}
	For(i,0,n){
		For(j,0,n){
			For(k,0,n){
				c[i][j] += (a[i][k]*b[k][j])%MOD;
				c[i][j] %= MOD;
			}
		}
	}
	return;
}
void matrix_exp(int a[MAX][MAX], int ans[MAX][MAX], int power){
	For (i,0,n){
		For(j,0,n) ans[i][j] = identity[i][j];
	}
	int temp[MAX][MAX];	
	while(power){
		if (power&1){
			multiply(a,ans,temp);
			For(i,0,n){
				For(j,0,n) ans[i][j] = temp[i][j];
			}
		}
		power=power>>1;
		multiply(a,a,temp);
		For(i,0,n){
			For(j,0,n) a[i][j] = temp[i][j];
		}
	}	
	return;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin>>n>>k;
	For(i,0,n){
		For(j,0,n) {
			if (i==j) identity[i][j] = 1;
			else identity[i][j] = 0;
			cin>>graph[i][j];
		}
	}
	int result[MAX][MAX];
	matrix_exp(graph,result,k);
	int path = 0;
	For(i,0,n){
		For(j,0,n){
			path += result[i][j];
			path%= MOD;
		}
	}
	cout<<path<<endl;
	return 0;
}


Measured memory_bytes: 384