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

int main(){
	string s;	cin>>s;
	int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
	//printf("%d %d %d %d\n",a,b,c,d);

	for(int x=0;x<8;x++){
		bool op1=x&1, op2=(x>>1)&1,op3=(x>>2)&1;
		int tmp=a;

		if(op1) tmp+=b;
		else tmp-=b;

		if(op2) tmp+=c;
		else tmp-=c;

		if(op3) tmp+=d;
		else tmp-=d;

		if(tmp==7){
			cout<<a;
			cout<<(op1? '+':'-');
			cout<<b;
			cout<<(op2? '+':'-');
			cout<<c;
			cout<<(op3? '+':'-');
			cout<<d<<"=7"<<endl;

			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
const int maxn=2e5+5;
int n,X,Y,tot;
int a[maxn],b[maxn],dep[maxn],fa[maxn][20];
int head[maxn],des[maxn<<1],nxt[maxn<<1];
int mark[maxn],q[maxn],mint[maxn],vis[maxn];
vector<int>e[maxn];
void adde(int x,int y){
	des[++tot]=y;nxt[tot]=head[x];head[x]=tot;
}
void dfs(int x){
	Rep(p,x)if(des[p]!=fa[x][0]){
		dep[des[p]]=dep[x]+1;
		fa[des[p]][0]=x;
		rep(i,1,19)fa[des[p]][i]=fa[fa[des[p]][i-1]][i-1];
		dfs(des[p]);
	}
}
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	per(i,19,0)if(dep[fa[x][i]]>=dep[y])x=fa[x][i];
	if(x==y)return x;
	per(i,19,0)if(fa[x][i]!=fa[y][i])x=fa[x][i],y=fa[y][i];
	return fa[x][0];
}
int dis(int x,int y){
	return dep[x]+dep[y]-2*dep[lca(x,y)];
}
void bfs(){
	int h=0,t=0,maxi=0;
	q[t++]=X;mint[X]=0;vis[X]=1;
	while(h!=t){
		int x=q[h++];
		maxi=max(maxi,dep[x]-1);
		if(mark[x]){
			puts("-1");
			return;
		}
		rep2(i,0,SZ(e[x])){
			int y=e[x][i];
			if(!vis[y]&&dep[y]-1>mint[x]+1)q[t++]=y,mint[y]=mint[x]+1,vis[y]=1;
		}
	}
	printf("%d\n",maxi<<1);
}
int main(){
	read(n);read(X);read(Y);
	rep(i,1,n-1)read(a[i]),read(b[i]);
	rep(i,1,n-1){
		int x,y;read(x);read(y);
		adde(x,y);adde(y,x);
	}
	dep[Y]=1;dfs(Y);
	rep(i,1,n-1){
		if(dis(a[i],b[i])>2)mark[a[i]]=mark[b[i]]=1;
		else e[a[i]].pb(b[i]),e[b[i]].pb(a[i]);
	}
	bfs();
	return 0;
}

Measured memory_bytes: 44288
D = int(input())
c = [int(x) for x in input().split()]
s = [input().split() for l in range(D)]

manzoku = 0
kyounomanzoku = 0
kyounotype = 0
d = 1
last = [0]*26

for p in range(D):
    print((p**2-87)%26+1)


"""
for p in range(D):
    #タイプはt[p]-1,0~25 満足度増加 s[p][t[p]] p+1日目 
    #typeを出力するときは＋１するのを忘れずに
    for t in range(26):
        if kyounomanzoku < int(s[p][t]):
            kyounomanzoku = int(s[p][t])
            kyounotype = t
    print(kyounotype+1)
    kyounomanzoku = 0
"""

Measured memory_bytes: 9664
sx,sy,tx,ty = map(int,input().split())

s =''

distx = tx - sx #x方向の距離
disty = ty - sy #y方向の距離

act = ['U','D','L','R']#[上、下、左、右]

#1
s += act[3]*distx + act[0]*disty

#2
s += act[2]*distx + act[1]*disty

#3
s += act[1] + act[3]*(distx + 1) + act[0]*(disty+1)+act[2]

#4
s += act[0] + act[2]*(distx + 1) + act[1]*(disty+1)+act[3]

print(s)


Measured memory_bytes: 3064
using DataStructures

function main()
    N, M = [parse(Int, s) for s in split.(readline())]
    edges = [Int[] for _ in 1:N]
  	for i in 1:M
        a, b = [parse(Int, s) for s in split.(readline())]
        push!(edges[a], b)
        push!(edges[b], a)
    end

    visited = falses(N)
    to_room = zeros(Int, N)
  
  	q = Queue{Int}()
	enqueue!(q, 1)
  
    while !isempty(q)
        pos = dequeue!(q)
        visited[pos] && continue
        visited[pos] = true
        for topos in edges[pos]
            iszero(to_room[topos]) && (to_room[topos] = pos)
            if !visited[topos]
        		enqueue!(q, topos)
            end
        end
    end
    if !all(visited)
        println("No")
        return
    end

    println("Yes")
    for i in 2:N
        println(to_room[i])
    end
end

main()


Measured memory_bytes: 242360
import math

ans = [0 for i in range(31)]
ans[0] = 1
ans[1] = 1
ans[2] = 2
for i in range(3, 31):
    ans[i] = ans[i-1] + ans[i-2] + ans[i-3]

while True:
    N = int(input())
    if N == 0:
        break

    print(math.ceil(ans[N]/3650))



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

using namespace std;

#define int long long

const int N = 5007, mod = 1e9+7;

int n, dp[N][N], f[N], inv[N], pow2[N];
string s;

int binpow(int a,int b){
	int res = 1;
	while(b){
		if(b&1) (res*=a)%=mod, --b;
		else (a*=a)%=mod, b>>=1;
	}
	return res;
}

int inverse(int x){
	return binpow(x,mod-2);
}

void preset(){
	f[0] = inv[0] = pow2[0] = 1;
	for(int i=1;i<N;++i){
		f[i] = (f[i-1] * i)%mod;
		inv[i] = inverse(f[i]);
		pow2[i] = (pow2[i-1]*2)%mod;
	}
}

int catalan(int x){
	int f1 = inverse(x+1)*f[2*x]%mod, f2 = inv[x]*inv[x]%mod;
	return (f1*f2)%mod; 
}

signed main(){
	preset();

	cin >> n >> s;
	dp[0][0] = 1;
	
	int m = s.length();
	for(int i=1;i<=n;++i){
		for(int j=0;j<=i;++j){
			(dp[i][j] += dp[i-1][max(j-1,0ll)]+2*dp[i-1][j+1])%=mod;
		}
	}
	cout << dp[n][m];
}

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

const double pi = acos(-1.0);

using data_type = complex<double>;
using matrix = vector<vector<data_type>>;

vector<data_type> fft(vector<data_type> v, bool inv = false) {
    const int n = v.size();
    double theta = 2 * pi / n * (inv ? -1 : 1);
    for(int m = n; m >= 2; m >>= 1) {
        int mh = m >> 1;
        data_type theta_i(0, theta);
        for(int i = 0; i < mh; ++i) {
            auto w = exp((data_type)i * theta_i);
            for(int j = i; j < n; j += m) {
                auto x = v[j] - v[j + mh];
                v[j] = v[j] + v[j + mh];
                v[j + mh] = w * x;
            }
        }
        theta *= 2;
    }
    for(int i = 0, j = 1; j < n - 1; ++j) {
        for(int k = n >> 1; k > (i ^= k); k >>= 1);
        if(j < i) {
            swap(v[i], v[j]);
        }
    }
    if(inv) {
        for(auto& x : v) x /= n;
    }
    return v;
}

matrix transpose(matrix a) {
    const int n = a.size(), m = a[0].size();
    matrix res(m, vector<data_type>(n));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            res[i][j] = a[j][i];
        }
    }
    return res;
}

matrix fft2d(matrix a, bool inv = false) {
    for(int t = 0; t < 2; ++t) {
        for(auto& v : a) {
            v = fft(move(v), inv);
        }
        a = transpose(move(a));
    }
    return a;
}

matrix conv2d(matrix a, matrix b) {
    const int nt = a.size() + b.size() - 1;
    const int mt = a[0].size() + b[0].size() - 1;
    int n = 1, m = 1;
    while(n < nt) n <<= 1;
    while(m < mt) m <<= 1;
    a.resize(n), b.resize(n);
    for(int i = 0; i < n; ++i) {
        a[i].resize(m);
        b[i].resize(m);
    }
    a = fft2d(move(a)), b = fft2d(move(b));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < m; ++j) {
            a[i][j] *= b[i][j];
        }
    }
    return fft2d(move(a), true);
}

int main() {
    int n, m, K, l; cin >> n >> m >> K >> l;
    matrix dat(n, vector<data_type>(n));
    for(int i = 0; i < n; ++i) {
        string s; cin >> s;
        for(int j = 0; j < n; ++j) {
            if(s[j] == 'X') {
                dat[i][j] = data_type{1, 0};
            }
        }
    }
    string s; cin >> s;
    vector<vector<int>> tcnt(m, vector<int>(m));
    for(int y = 0, x = 0, i = 0; i < (int)s.size(); ++i) {
        if(s[i] == 'U') --y;
        if(s[i] == 'D') ++y;
        if(s[i] == 'R') ++x;
        if(s[i] == 'L') --x;
        tcnt[y][x]++;
    }
    matrix cnt(m, vector<data_type>(m));
    for(int i = 0; i < m; ++i) {
        for(int j = 0; j < m; ++j) {
            cnt[i][j] = data_type{(double)tcnt[i][j], 0};
        }
    }

    auto res = conv2d(cnt, dat);
    int ans = 0;
    for(int i = 0; i < m; ++i) {
        for(int j = 0; j < m; ++j) {
            const int val = (int)(real(res[i][j]) + 0.5);
            ans += val >= K;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 61788
use std::io;
fn main() {
    let n: i32 = get_line().parse().unwrap();
    let mut res = 0;
    for _ in 0..n {
        let ac: Vec<i32> = get_line().split(' ').map(|x| x.trim().parse().unwrap()).collect();
        res += ac[1] - ac[0] + 1;
    }
    println!("{}", res);
}

fn get_line() -> String {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    return String::from(line.trim())
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
vector<string> v;
int n,len,ans;
string s;

bool check(char c){
  return c=='a'||c=='i'||c=='u'||c=='e'||c=='o';
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    len=0;
    ans=(1e9);
    for(int i=0;i<n;i++){
      cin>>s;
      string t;
      t+=s[0];
      for(int j=1;j<s.size();j++)
	if(check(s[j-1]))t+=s[j];
      len=max(len,(int)t.size());
      v.push_back(t);
    }
    for(int i=1;i<=len;i++){
      vector<string> u;
      for(int j=0;j<n;j++)
	u.push_back(v[j].substr(0,i));
      int f=0;
      for(int j=0;j<n;j++)
	for(int k=j+1;k<n;k++)
	  if(u[j]==u[k])f=1;
      if(!f)ans=min(ans,i);
    }
    if(ans!=(1e9))cout<<ans<<endl;
    else cout<<-1<<endl;
    v.clear();
  }
  return 0;
}

Measured memory_bytes: 1228
H, W = map(int, input().split())

if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()

ans = min(W, H)
for i in range(1, H):
    tmp1 = W//2*(H-i)
    tmp2 = tmp1 if W % 2 == 0 else tmp1+H-i
    tmp3 = i*W
    ans = min(ans, max(abs(tmp1-tmp2), abs(tmp2-tmp3), abs(tmp3-tmp1)))
for i in range(1, W):
    tmp1 = H//2*(W-i)
    tmp2 = tmp1 if H % 2 == 0 else tmp1+W-i
    tmp3 = i*H
    ans = min(ans, max(abs(tmp1-tmp2), abs(tmp2-tmp3), abs(tmp3-tmp1)))
print(ans)


Measured memory_bytes: 3064
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

for y in range(h):
    for x in range(w):
        if s[y][x] == ".":
            continue
        if 0 < x < w-1:
            if 0 < y < h-1:
                if s[y][x-1] == "." and s[y][x+1] == "." and s[y-1][x] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            elif y == 0:
                if s[y][x-1] == "." and s[y][x+1] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            else:
                if s[y][x-1] == "." and s[y][x+1] == "." and s[y-1][x] == ".":
                    print("No")
                    exit()
        elif x == 0:
            if 0 < y < h-1:
                if s[y][x+1] == "." and s[y-1][x] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            elif y == 0:
                if s[y][x+1] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            else:
                if s[y][x+1] == "." and s[y-1][x] == ".":
                    print("No")
                    exit()
        else:
            if 0 < y < h-1:
                if s[y][x-1] == "." and s[y-1][x] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            elif y == 0:
                if s[y][x-1] == "." and s[y+1][x] == ".":
                    print("No")
                    exit()
            else:
                if s[y][x-1] == "." and s[y-1][x] == ".":
                    print("No")
                    exit()
print("Yes")

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

#define debug(x) (cerr << #x << " = " << x << endl;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

const int maxn = 2e5 + 100;


ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

int cnt[10][10];

int main()
{
  int n;
  ios::sync_with_stdio(0);
  cin >> n;
  for(int i = 1; i <= n ; i++)
  {
    int x = i;
    int last = x % 10;
    int first = x % 10;
    x /= 10;
    while(x)
    {
      first = x % 10;
      x /= 10;
    }
    cnt[first][last]++;
  }

  ll ans = 0;

  for(int i = 0; i < 10; i++)
  {
    for(int j = 0; j < 10; j++)
    {
      // cout << i << ' ' << j << " -> " << cnt[i][j] << endl;
      ans += (cnt[i][j] * (cnt[j][i])); 
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

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

#ifdef LOCAL//compile with -DLOCAL
#define debug(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<(x)<<endl
#define debug_vec(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = ";\
  rep(i,sz(x)){cerr<<x[i]<<" ";}cerr<<endl
#define debug_mat(x) cerr<<"LINE"<<__LINE__<<" : "<<#x<<" = "<<endl;\
  rep(i,sz(x)){rep(j,sz(x[i])){cerr<<x[i][j]<<" ";}cerr<<endl;}cerr<<endl
#else
#define debug(x) void(0)
#define debug_vec(x) void(0)
#define debug_mat(x) void(0)
#endif

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


int op(int a, int b){
  return max(a, b);
}

int e(){
  return -1;
}

int target;
bool f(int v){
  return v < target;
}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,Q;
  cin >> N >> Q;
  vector<int> A(N);
  rep(i,N)  cin >> A.at(i);

  segtree<int, op, e> seg(A);
  rep(_,Q){
    int t;
    cin >> t;
    if(t == 1){
      int x,v;
      cin >> x >> v;
      x--;
      seg.set(x, v);
    }
    else if(t == 2){
      int l,r;
      cin >> l >> r;
      l--;
      r--;
      cout << seg.prod(l, r+1) << endl;
    }
    else if(t == 3){
      int x,v;
      cin >> x >> v;
      x--;
      target = v;
      cout << seg.max_right<f>(x) + 1 << endl;
    }
  }

  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N, M; cin >> N >> M;
    vi P(M), Y(M);
    vvi year(N+1);
    
    REP(i, M)
    {
        cin >> P[i] >> Y[i];
        year[P[i]].push_back(Y[i]);
    }
    REP1(i, N) sort(ALL(year[i]));
    cout.setf(ios::right, ios::adjustfield);
    cout.fill('0');
    REP(i, M)
    {
        int x = (int)(lower_bound(ALL(year[P[i]]), Y[i]) - year[P[i]].begin()) + 1;
        cout << setw(6) << P[i] << setw(6) << x << endl;
    }
}

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

    solve();

    return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    S = '0' + S;
    int lenS = S.length();
    ll dp[lenS][2]{};
    dp[0][0] = 1;
    for(int i = 0; i < lenS-1; i++){
        for(int smaller = 0; smaller <= 1; smaller++){
            for(int d = 0; d <= (smaller ? 1 : S[i+1]-'0'); d++){
                if(d == 0) dp[i+1][smaller || (d < S[i+1]-'0')] += dp[i][smaller];
                else dp[i+1][smaller || (d < S[i+1]-'0')] += dp[i][smaller]*2;
            }
        }
        dp[i+1][0] %= mod;
        dp[i+1][1] %= mod;
    }
    cout << (dp[lenS-1][0] + dp[lenS-1][1]) % mod << endl;
    return 0;
}

Measured memory_bytes: 1900
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) ll x;cin>>x; while(x--)
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin>>n;
	if(n%1000==0)
		cout<<0;
	else
		cout<<1000-(n%1000);
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    if (s.equals("AAA") || s.equals("BBB")) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  } 
}


Measured memory_bytes: 23636
fac=Proc.new{|m|(1..m).to_a.inject(1){|f,i|f*i}}
com=Proc.new{|m,k|(k.zero?)?1:(m-k+1..m).inject(:*)/fac[k]}
n=gets.to_i
xy=[]
n.times{xy<<gets.split.map(&:to_i)}
s=0
xy.combination(2).each{|a,b|s+=Math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)}
puts s*(n-1)/com[n,2]

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


void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}




int main()
{
    init();
    cout << fixed << setprecision(20);
    int n ;cin>>n; cout << 2*(22*1.0/7)*n;

}




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

#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define db1(x) cout<<#x<<" : "<<x<<endl;
#define db2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define db3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;

typedef long long int ll;
typedef long double ld;

const int  N = 2e5+5;
const int inf = INT_MAX;
const int MOD = 1e9+7;

void solve()
{
   ll n;
   cin >> n;
   vector<ll> a(n+15,1);
   a[1]=1;
   ll i,j;
   for(i=2;i<=n;i++)
   {
      for(j=1;j*1LL*i<=n;j++)
      {
         a[i*1LL*j]++;
      }
   }
   ll ans=0;
   for(i=1;i<=n;i++)
   {
      ans+=i*1LL*a[i];
   }
   cout << ans << endl;
}

int32_t main()
{
   IOS;
   //freopen("input.txt", "rt", stdin);
   //freopen("output.txt", "wt", stdout);
   int t=1;
   //cin >> t;
   for(int i=1;i<=t;i++)
   {
      //cout<<"Case #"<<i<<": ";
      solve();
   }
   return 0;
}
/*==============================================================================================================================================================*/


Measured memory_bytes: 81340
#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

int main() {
    int H,W;
    cin >> H >> W;
    for(int i = 0; i < W+2; i++){
        cout << "#";
    }
    cout << endl;
    for(int i = 0;i < H; i++){
        string s;
        cin >> s;
        cout << "#" << s << "#" << endl;
    }
   for(int i = 0; i < W+2; i++){
        cout << "#";
    }
    cout << endl;
   
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import sys


def bin_tree(lst, n):
    """
        tree[0]: node
        tree[1]: parent
        tree[2]: sibling
        tree[3]: degree
        tree[4]: depth
        tree[5]: height
    """
    info = [[-1, -1, -1, -1, -1, -1] for n in range(0, n)]
    degree = 0
    for node, left, right in lst:
        if left >= 0:
            info[left][1] = node
            info[left][2] = right
            degree += 1

        if right >= 0:
            info[right][1] = node
            info[right][2] = left
            degree += 1

        info[node][0] = node
        info[node][3] = degree

        degree = 0

    root = -1
    for node in info:
        root = node[0]
        if node[1] == -1:
            break

    get_depth(lst, root, info)
    get_height(lst, root, info)
    print_info(info)


def get_height(tree, root, info):
    def _get_height(node, depth):
        if node == -1:
            return 0

        left_height = _get_height(tree[node][1], depth + 1)
        right_height = _get_height(tree[node][2], depth + 1)

        if left_height > right_height:
            info[node][5] = left_height
        else:
            info[node][5] = right_height

        return info[node][5] + 1

    _get_height(root, 0)


def get_depth(tree, root, info):
    def _get_depth(node, depth):
        if node == -1:
            return

        info[node][4] = depth
        _get_depth(tree[node][1], depth + 1)
        _get_depth(tree[node][2], depth + 1)

    _get_depth(root, 0)


def print_info(info):
    for node, parent, sibling, degree, depth, height in info:
        if parent == -1:
            _type = "root"
        elif degree != 0:
            _type = "internal node"
        else:
            _type = "leaf"

        print("node {0}: parent = {1}, sibling = {2}, degree = {3}, depth = {4}, height = {5}, {6}".format(node, parent, sibling, degree, depth, height, _type))


if __name__ == "__main__":
    n = int(input())
    lst = [[int(n) for n in val.split()] for val in sys.stdin.readlines()]
    lst.sort(key=lambda x: x[0])
    bin_tree(lst, n)

Measured memory_bytes: 5640
n = int(input())
v = [int(i) for i in input().split(" ")]

h_even = [[i, 0] for i in range(0, 10**5 + 1)]
h_odd = [[i, 0] for i in range(0, 10**5 + 1)]

for i in range(0, n // 2):
    h_even[v[2 * i]][1] += 1
    h_odd[v[2 * i + 1]][1] += 1
    
h_even.sort(reverse=True, key=lambda k: k[1])
h_odd.sort(reverse=True, key=lambda k:k[1])

if h_even[0][0] == h_odd[0][0]:
    print(min(n - h_even[0][1] - h_odd[1][1], n - h_even[1][1] - h_odd[0][1]))
else:
    print(n - h_even[0][1] - h_odd[0][1])

Measured memory_bytes: 35044
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    ll sum = 0;
    int minus = 0;
    ll mn = INF;
    ll a;
    REP(i, n) {
        cin >> a;
        if (a < 0) minus++;
        sum += abs(a);
        chmin(mn, abs(a));
    }
    if (minus % 2 == 0) cout << sum << endl;
    else cout << sum - mn * 2 << endl;
}


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main()
{
    int a[1000],i,count;
    for(i=1;i<=5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {
            count=i;
        }
    }
    cout<<count<<endl;
    return 0;
}


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

#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2")

using namespace std;

#define f first
#define s second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define up(x, v) upper_bound(all(x), v)
#define low(x, v) lower_bound(all(x), v)
#define bin(x, v) binary_search(all(x), v)
#define FOR(k, a, b) for(int k = (a); k < (b); ++k)
#define ROF(k, a, b) for(int k = (a); k > (b); --k)
#define fn(k, n) for(int k = 0; k < n; ++k)

#define EPS 1.0e-9

#define X real()
#define Y imag()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using point = pair<double, double>;
using Vector = complex<double>;

#define MOD 1000000007

ll expmod(int n, int p) {

	if(p == 0) return 1LL;

	ll r = expmod(n, p >> 1);

	r = r * r % MOD;
	
	if(p & 1) return r * n % MOD;

	return r;
}

ll C(int n, int p) {

	int k = n - p;
	ll x = 1, y = 1;

	if(k < p) swap(k, p);

	while(p > 0) {

		x = (x * n--) % MOD;
		y = (y * p--) % MOD;
	}

	return x * expmod(y, MOD - 2) % MOD;
}

int main() {

	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, a, b;

	cin >> n >> a >> b;

	if(n == 2)
		cout << 0 << '\n';

	else {

		ll x = (expmod(2, n) - 1) % MOD;

		x = (x - C(n, a) - C(n, b)) % MOD;

		cout << (x + MOD) % MOD << '\n';
	}

    return 0;
}


Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        d: [i32; n]
    }
    let mut ans = 0;

    for i in 0..(n - 1) {
        for j in i + 1..n {
            ans += d[i] * d[j];
        }
    }
    println!("{}", ans);
}


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

using namespace std;
int main()
{
  int n;
  scanf("%d",&n);
  int cnt=0;
  while(n!=0)
  {
    if(n%10==2)
        cnt++;
    
    n/=10;
  }
  
  printf("%d",cnt);
}
  
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 1000000007,dp[305][305][305] = {};
int main(){
	ll i,j,k,n,m;
	cin >> n >> m;
	dp[0][1][0] = 1;
	for(i=0;i<m;i++){
		for(j=1;j<=n;j++){
			for(k=0;k<=n - j;k++){
				(dp[i + 1][j + k][0] += j*dp[i][j][k]) %= mod;
				(dp[i + 1][j][k] += k*dp[i][j][k]) %= mod;
				(dp[i + 1][j][k + 1] += (n - j - k)*dp[i][j][k]) %= mod;
			}
		}
	}
	cout << dp[m][n][0] << endl;
}

Measured memory_bytes: 218624
A,B,C,D = map(int,input().split())


ans = 0

if B < C or D < A:
    ans = 0
elif A <= C and D <= B:
    ans = D - C
elif C<=A and B<= D:
    ans = B - A
elif C<=A and D<=B:
    ans = D - A
else:
    ans = B - C
print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  vector<int> a(6);
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5];
  vector<int> b(4);
  b[0]=0;
  b[1]=0;
  b[2]=0;
  b[3]=0;
  for (int i=0; i<6; i++) {
    b[a[i]-1]=b[a[i]-1]+1;
  }
  sort(b.begin(),b.end());
  if (b[0]==1 && b[1]==1 && b[2]==2 && b[3]==2) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

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

int main(){
  int N,K;
  string S;
  cin >>N>>K>>S;
  
  switch (S.at(K-1)) {
    case 'A':
	  S.at(K-1)='a';
      break; 
		
	case 'B':
        S.at(K-1)='b';
      break; 
      
    case 'C':
		  S.at(K-1)='c';
      break; 
		
	default:
		break;
	}
  
cout <<S<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
using namespace std;


int main ()
{

int n,max=0,sum=0;
cin >> n;
int arr;

while(n-->0)
{
  cin >> arr;
  sum+=arr;
  
  if(arr>max)
  {
	  max=arr;
  }
}

if(max< (sum-max))
{
	 cout << "Yes" << endl;
}
else
{
	cout << "No" << endl;
}
	return 0;
}











Measured memory_bytes: 3056
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#if 1
#define DEBUG(x) do{cerr << #x << "=" << x << endl;}while(0);
#else
#define DEBUG
#endif

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

	bool f = false;

	for( int i=1; i< s.size(); ++i ){
		if(s[i-1] == s[i]){
			f = true;
		}
	}

	if( f ){
		cout << "Bad" << endl;
	}
	else {
		cout << "Good" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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; }

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) {
    int c, d;
    cin >> c >> d;
    if (c == d) a[i] = 1;
  }
  bool ok = false;
  rep(i, n-2) {
    if (a[i] && a[i+1] && a[i+2]) ok = true;
  }
  if (ok) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3632
S = input()

N_cnt = S.count('N')
W_cnt = S.count('W')
S_cnt = S.count('S')
E_cnt = S.count('E')

if ((N_cnt > 0 and S_cnt > 0) or (N_cnt == 0 and S_cnt == 0)) \
	and ((W_cnt > 0 and E_cnt > 0) or (W_cnt == 0 and E_cnt == 0)):
	print('Yes')
else:
	print('No')


Measured memory_bytes: 38256
#include<iostream>
#include<cstdio>
using namespace std;
struct Edge
{
    int to,next,cost;	
}e[400005];
int head[100005],cnt=0;
bool vis[100005];
int d[100005];
bool use[100005];
void addedge(int from,int to,int cost)
{
    e[++cnt].to=to;
    e[cnt].cost=cost;
    e[cnt].next=head[from];
    head[from]=cnt;
}
bool flag=0;
void dfs(int x)
{
    vis[x]=1;
    for(int i=head[x];i;i=e[i].next)
    {
        int w=e[i].cost,v=e[i].to;
        if(d[v]>d[x]+w)
        {
            d[v]=d[x]+w;
            if(vis[v])
            {
                flag=1;
                return;
            }
            dfs(v);	
        }	
    } 
    vis[x]=0;
    return;
}
inline int read()
{
    int s=0,f=1;char x=getchar();
    while(!isdigit(x))
    {
        if(x=='-') f=-1;
        x=getchar();
    }
    while(isdigit(x))
    {
        s=(s<<1)+(s<<3)+(x^48);
        x=getchar();
    }
    return s*f;
}
int main()
{
    int n,m;
    n=read();m=read();
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        x=read();y=read();z=read();
        addedge(y,x,z);
        addedge(x,y,-z);
    }
    flag=0;
    for(int i=1;i<=n;i++)
    {
        d[i]=0;
        if(!use[i])
        {
            use[i]=1;
            dfs(i);
        }	
    }
    if(flag) cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 7808
/* March 28 2020 */

#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>

#define ll long long

int main(void) {
    ll k, n; scanf("%lld %lld", &k, &n);
    ll vals[n];
    for (ll i = 0; i < n; ++i) scanf("%lld", &vals[i]);
    ll sub = vals[0];
    for (ll i = 0; i < n; ++i) vals[i] -= sub;

    ll ans = vals[n - 1];
    for (ll i = 1; i < n; ++i) 
        ans = std::min(ans, vals[i - 1] + k - vals[i]);
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

string n;
int k;
ll dp[101][2][4];

ll rec(int digit, bool tight, int sum){
    if(dp[digit][tight][sum] != -1){
        return dp[digit][tight][sum];
    }
	if(digit == n.size()){
		return sum == 0;
	}
	int x = n[digit] - '0';
	int lim = (tight ? x : 9);
	ll res = 0;
	for(int i = 0; i <= lim; i++){
        if(i == 0){
            res += rec(digit + 1, tight && i == lim, sum);
        }else{
            if(sum - 1 < 0) continue;
            res += rec(digit + 1, tight && i == lim, sum - 1);
        }
	}
	return dp[digit][tight][sum] = res;
}

signed main(){
    cin >> n;
    cin >> k;
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 1, k) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


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

typedef struct{
  int h,r;
}mat;

bool lessh(const mat&l,const mat&r){return l.h<r.h;};
bool lessr(const mat&l,const mat&r){return l.r<r.r;};





main(){
  int n;
  while(cin>>n,n){
    vector<PI> hr;
    int low[200]={0},ans=0;
    int h,r;
    rep(i,n){
      cin>>h>>r;
      hr.pb(mp(h,r));
    }

    int m;
    cin>>m;
    rep(i,m){
      cin>>h>>r;
      hr.pb(mp(h,r));
    }


    sort(hr.begin(),hr.end());

    rep(i,n+m){
      rep(j,i){
	if(hr[j].F<hr[i].F && hr[j].S<hr[i].S){
	  low[i]=max(low[i],low[j]+1);
	  ans=max(ans,low[i]);
	}
      }
    }
    //rep(i,m+n)cout<<hr[i].h<<" "<<hr[i].r<<" "<<low[i]+1<<endl;
    cout<<ans+1<<endl;
  }
}

Measured memory_bytes: 0
data class Test(val b: Long, val l: Long, val u: Long)

fun main(args: Array<String>) {
  val (nRaw, x) = readLine()!!.split(" ").map { it.toLong() }
  val n = nRaw.toInt()
  val tests = Array(n, {
    val (b, l, u) = readLine()!!.split(" ").map { it.toLong() }
    Test(b, l, u)
  })
  var currentDiff = tests.map { -it.l * it.b }.sum()
  fun maxGain(test: Test): Long = test.l * test.b + test.u * (x - test.b)
  tests.sortByDescending { maxGain(it) }

  var ans = 0L
  for (i in 0 until n) {
    if (currentDiff + maxGain(tests[i]) <= 0) {
      ans += x
      currentDiff += maxGain(tests[i])
    } else {
      val min1 = (i until n).filter { currentDiff + maxGain(tests[it]) >= 0 }
          .map {
            if (tests[it].l * tests[it].b >= -currentDiff) {
              (-currentDiff + tests[it].l - 1) / tests[it].l
            } else {
              tests[it].b + (-currentDiff - tests[it].l * tests[it].b + tests[it].u - 1) / tests[it].u
            }
          }
          .min()!!
      if (min1 < 0) throw RuntimeException()
      var min2 = x
      for (k in 0 until i) {
        val tmpDiff = currentDiff + maxGain(tests[i]) - maxGain(tests[k])
        val a = if (tests[k].l * tests[k].b >= -tmpDiff) {
          (-tmpDiff + tests[k].l - 1) / tests[k].l
        } else {
          tests[k].b + (-tmpDiff - tests[k].l * tests[k].b + tests[k].u - 1) / tests[k].u
        }
        if (a <= x) {
          min2 = Math.min(min2, a)
        }
      }
      if (min2 < 0) throw RuntimeException()
      ans += Math.min(min1, min2)
      break
    }
  }

  // if (currentScore < 0) throw RuntimeException()

  println(ans)
}

Measured memory_bytes: 86092
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  int h,a;
  cin>>h>>a;
  if(h%a==0){
    cout<<h/a;
  }else{
    cout<<h/a+1;
  }
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
int ca[200005];
int cb[200005];
int main(){
    int n,m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        if(a==1)ca[b]++;
        else if(b==n)cb[a]++;
    }
    for(int i=1;i<=n;i++){
        if(ca[i]>0 && cb[i]>0){
            cout << "POSSIBLE";
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
}

Measured memory_bytes: 5164
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const int MAXN=1e5;
int n_pnt,n_edg;
struct NODE{
    int p,val;//val+p*x>0
    NODE(){}
    NODE(int a,int b){p=a;val=b;}
};
struct QUEUE{
    int u,p;//val+p*x>0
    long long val;
    QUEUE(){}
    QUEUE(int a,int b,long long c){u=a;p=b;val=c;}
};
vector<pair<int,int> > lnk[MAXN+5];
long long vis[2][MAXN+5];//vis[0][i]-x>0 && vis[1][i]+x>0 -> x<vis[0] && x>-vis[1]
inline int G(int p){return p==1;}
long long MIN=-1e15,MAX=1e15;
int main()
{
    fill(vis[0],vis[0]+MAXN+5,1e15);
    fill(vis[1],vis[1]+MAXN+5,1e15);
    scanf("%d%d",&n_pnt,&n_edg);
    for(int i=0,u,v,l;i<n_edg;i++)
        scanf("%d%d%d",&u,&v,&l),
        lnk[u].push_back(make_pair(v,l)),lnk[v].push_back(make_pair(u,l));
    queue<QUEUE> que;
    que.push(QUEUE(1,1,0));
    while(!que.empty())
    {
        QUEUE fro=que.front();que.pop();
        for(int i=0;i<lnk[fro.u].size();i++)
        {
            int v=lnk[fro.u][i].first,l=lnk[fro.u][i].second;
            long long val=l-fro.val;int p=fro.p==1? -1:1;
            if(vis[G(p)][v]!=1e15)
            {
                if(val!=vis[G(p)][v])
                {
                    printf("%d\n",0);
                    return 0;
                }
                else
                    continue;
            }
            vis[G(p)][v]=val;
            if(G(p))
                MIN=max(MIN,max((long long)0,-vis[1][v]));
            else
                MAX=min(MAX,vis[0][v]);
            que.push(QUEUE(v,p,val));
        }
    }
    long long ans=-1;
    for(int i=1;i<=n_pnt;i++)
        if(vis[0][i]!=1e15 && vis[1][i]!=1e15)
        {
            int res=(vis[0][i]-vis[1][i])/2;
            if(res<0) {printf("0\n");return 0;}
            if(ans==-1) ans=res;
            if(ans!=res) {printf("0\n");return 0;}
        }
    if(ans!=-1)
    {
        if(MIN<ans && ans<MAX)
            printf("%d\n",1);
        else
            printf("%d\n",0);
        return 0;
    }
    if(MAX-MIN-1<0) printf("%d\n",0);
    else printf("%lld\n",MAX-MIN-1);
    return 0;
}

Measured memory_bytes: 9716
#include<stdio.h>

int main(void)
{
    int a,b,c;

    scanf("%d %d %d",&a,&b,&c);
    if(((a>=1&&a<=100)&&(b>=1&&b<=100))&&(c>=1&&c<=100))
    {
        if(((a!=b)&&(a!=c))&&(b!=c)){
            printf("3\n");
        }
        else if(((a==b)&&(b!=c))||(((a==c)&&(b!=c))||(b==c&&(a!=b&&a!=c))))
            printf("2\n");
       else
            printf("1\n");
    }
    return 0;
}


Measured memory_bytes: 128
x = int(input())
for i in range(3, x+1):
    if i % 3 == 0:
        print(' ' + str(i), end='')
    elif i % 10 == 3:
        print(' ' + str(i), end='')
    elif '3' in str(i):
        print(' ' + str(i), end='')
print()



Measured memory_bytes: 5876
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
   int h,w,n;
   cin>>h>>w>>n;
   int ny,nx;
   cin>>ny>>nx;
   string s,t;
   cin>>s>>t;
   int l=0,r=w+1;
   if(s[n-1]=='L')l++;
   if(s[n-1]=='R')r--;
   bool able=true;
   for(int i=n-2;i>=0;i--){
       if(t[i]=='L'&&r<=w)r++;
       if(t[i]=='R'&&l>0)l--;
       if(s[i]=='L')l++;
       if(s[i]=='R')r--;
       if(abs(l-r)<=1)able=false;
   }
   if(l>=nx||nx>=r)able=false;
   int u=0,d=h+1;
   if(s[n-1]=='U')u++;
   if(s[n-1]=='D')d--;
   for(int i=n-2;i>=0;i--){
       if(t[i]=='U'&&d<=h)d++;
       if(t[i]=='D'&&u>0)u--;
       if(s[i]=='U')u++;
       if(s[i]=='D')d--;
       if(abs(u-d)<=1)able=false;
   }
   if(u>=ny||ny>=d)able=false;
   if(able)cout<<"YES"<<"\n";
   else cout<<"NO"<<"\n";
}

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

signed
main(){
		int N;
		cin >> N;
		vector<int> a(N), is_same(N);

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

		for(int l=0;l<=N-1;l++)
		{
				int r = (N - 1) - l;
				is_same[l] = abs(l-r);
		}

		sort(a.begin(), a.end());
		sort(is_same.begin(), is_same.end());

		bool flag = true;
		for(int i=0;i<N;i++)
		{
				if(a[i]!=is_same[i])
				{
						flag = false;
						break;
				}
		}

		if(!flag)
		{
				cout << 0 << endl;
				return 0;
		}

		ll ans = 1;
		int key = N / 2;
		for(int i=0;i<key;i++)
		{
				ans *= 2;
				ans %= MOD;
		}
		cout << ans << endl;
}

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

#define ff first
#define ss second
#define pb push_back
#define int long long

bool comp(int a,int b){
return a>b ;	
}


bool foo(int arr[],int n,int k){
	
	if(n==0 || k==0)
	return 0;
	
	for(int i=0;i<n;i++){
		if(k>=arr[i]){	
			bool state=foo(arr,n,k-arr[i]);
			if(!state)
				return 1;
		}
	}
	return 0;
}

signed main(){

//int mod=1000000007;

#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#else
// online submission
#endif

int n,k;
cin >> n >> k;

int arr[n];
for(int i=0;i<n;i++)
cin >> arr[i] ;


int dp[k+1]={0};

for(int i=0;i<=k;i++){
	for(int j=0;j<n;j++){
		
		if(i>=arr[j] && dp[i-arr[j]]==0 ){
				dp[i]=1;
				break;
		}
	}
}

bool ans=dp[k];
if(ans)
cout<<"First";
else cout<<"Second";

	return 0;
    
}




Measured memory_bytes: 4368
def parent(i)
  i/2
end

def left(i)
  i*2
end

def right(i)
  i*2 + 1
end

def extract(i)
  l = left(i)
  r = right(i)
  h = A.length

  # printf "extract %d\n",i
  # p A
  # printf "l %d  r %d  h %d\n",l,r,h

  if l < h && A[l] > A[i]
    @largest = l
  else
    @largest = i
  end

  if r < h && A[r] > A[@largest]
    @largest = r
  end

  if @largest != i
    A[i], A[@largest] = A[@largest], A[i]
    extract(@largest)
  end
end

def insert(i)
  @parent = parent(i)
  if @parent == 0
    return
  end

  if A[i] > A[@parent]
    A[i], A[@parent] = A[@parent], A[i]
    insert(@parent)
  end
end

A = Array.new
A << 0

until (str=gets.chomp) == "end"
  # p A
  if str == "extract"
    puts A[1]
    A[1] = A.pop
    extract(1)
  else
    str = str.split(" ")
    A << str[1].to_i
    insert(A.length-1)
  end
end



Measured memory_bytes: 14828
import fractions
A, B, C, D = map(int, input().split())

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

ans = B - A + 1
ans -= B//C - (A-1)//C
ans -= B//D - (A-1)//D
ans += B//CD - (A-1)//CD

print(ans)


Measured memory_bytes: 5048
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int a,b;cin>>a>>b;
  if(a%3==0||b%3==0||(a+b)%3==0)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                
using namespace std;
typedef long long lint;
#define FOR(i,o,n) for(auto i = (o); (i) < (n); ++(i))
#define REP(i,n) FOR(i,0,n) 
#define REPR(i,n) for(auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr,v) for(auto itr=v.begin(); itr != v.end(); ++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define Vi2(name,h,w)  vector< vector<int> > name((h), vector<int>(w));

int main(void){
	lint N, M; cin >> N >> M;
	vector<lint> inpV(M); REP(i,M) cin >> inpV[i];
	sort(inpV.begin(), inpV.end());

	vector<lint> disV(M-1); 
	for(int i = 1; i < M; i++){
		disV[i-1] = inpV[i] - inpV[i-1];
	} 
	sort(disV.begin(), disV.end());

	lint sum = 0; 
	REP(i, M-N) sum += disV[i];
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 1792