akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

struct prog {
    int s, t, c;
};

bool operator<(prog a, prog b) {
    return (a.c == b.c ? a.s < b.s : a.c < b.c);
}

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

    int N, C;
    cin >> N >> C;

    vector<prog> dat(N);
    for (int i = 0; i < N; ++i)
        cin >> dat[i].s >> dat[i].t >> dat[i].c;

    sort(dat.begin(), dat.end());
    vector<int> cnt(100005);
    for (int i = 0; i < N; ++i) {
        cnt[dat[i].s - 1]++;
        if (i + 1 < N && dat[i].c == dat[i + 1].c && dat[i].t == dat[i + 1].s) {
            cnt[dat[i + 1].s - 1]--;
            continue;
        }
        cnt[dat[i].t]--;
    }

    int ans = 0;
    for (int i = 0; i <= 100000; ++i) {
        cnt[i + 1] += cnt[i];
        ans = max(ans, cnt[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include <vector>
#include <algorithm>
using namespace std;

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
};

int main() {
    int N, Q;
    scanf("%d %d", &N, &Q);
    int a[N];
    for(int i = 0; i < N; ++i){
        scanf("%d", a + i);
    }
    int lefts[Q], rights[Q], ids[Q];
    for (int i = 0; i < Q; ++i) {
        scanf("%d %d", lefts + i, rights + i);
        --lefts[i];
        ids[i] = i;
    }
    sort(ids, ids + Q, [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) printf("%d\n", res[i]);
    return 0;
}

Measured memory_bytes: 21652
#include<stdio.h>
#include<string.h>

int main(){

  int N,L=0;
  scanf("%d %d",&N,&L);

  char S[N][L+1],tmp[L+1];
  for(int i=0; i<N; i++){
    scanf("%s",S[i]);
  }

  for(int k=0; k<N-1; k++){
    for(int j=0; j<N-1; j++){
      if(strcmp(S[j],S[j+1])>0){
       strcpy(tmp,S[j+1]);
       strcpy(S[j+1],S[j]);
       strcpy(S[j],tmp);            
     }
    }
  } 

  for(int y=0; y<N; y++){
    printf("%s",S[y]);
  }

  return 0;
}

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

int N, K, L[300009], R[300009], bit[300009], num[300009];
vector<int>x[100009];
vector<pair<int, int>>G[300009];

void add(int pos, int x) {
	while (pos <= N) {
		bit[pos] += x; pos += (pos&-pos);
	}
}
int sum(int pos) {
	int s = 0;
	while (pos >= 1) { s += bit[pos]; pos -= (pos&-pos); }
	return s;
}

int main() {
	cin >> K >> N;
	for (int i = 1; i <= K; i++) {
		cin >> L[i] >> R[i];
		G[L[i]].push_back(make_pair(1, i));
		G[R[i]].push_back(make_pair(2, i));
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= N; j += i) x[j].push_back(i);
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < G[i].size(); j++) { if (G[i][j].first == 2) continue; add(i, 1); }

		for (int j : x[i]) {
			int v1 = i - j, v2 = i;
			int F = sum(v2) - sum(v1);
			num[j] += F;
		}

		for (int j = 0; j < G[i].size(); j++) { if (G[i][j].first == 1) continue; add(L[G[i][j].second], -1); }
	}
	for (int i = 1; i <= N; i++) cout << num[i] << endl;
	return 0;
}

Measured memory_bytes: 31096
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N, M; cin >> N >> M;
    vi A(N), B(N); REP(i, N) cin >> A[i] >> B[i];

    vector<pii> v;
    REP(i, N) v.push_back(pii(A[i], B[i]));

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

    ll ans = 0;
    int cnt = 0;
    int i = 0, j = 0;
    while(true) {
        if (cnt >= M) break;

        if (i<v[j].second) {
            ans += v[j].first;
            i++;
            cnt++;
        } else {
            i = 0;
            j++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2168
# 

s=input() #0,1,Bからなる文字列を入力
a="" #aは求める文字列
l=0 #lはaの長さ

for i in s:
    if i=="B": #iがBなら末尾を消去
        a=a[0:l-1] 
        l-=1
    else: #iがB出なければaの末尾にiを付ける
        a+=i
        l+=1
    if l<0: #lは負にならない
        l=0

print(a)


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
from fractions import gcd


def read():
    A, B, C = map(int, input().strip().split())
    return A, B, C

def solve(A, B, C):
    m = gcd(A, B)
    return "YES" if C % m == 0 else "NO"

if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 5076
import scala.io.StdIn
import scala.collection.mutable.{Map => MMap}

object Main extends App {
  val line = StdIn.readInt()

  val map = MMap[String,Int]().withDefaultValue(0)

  for(_ <- 1 to line){
    map(StdIn.readLine()) += 1
  }

  for(str <- Array("AC","WA","TLE","RE")){
    println(s"$str x ${map(str)}")
  }
}


Measured memory_bytes: 56420
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
#define cu cout<<
#define en endl
#define sp " "
#include<cstdio>
#include<cstring>
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
/*bool isprime(ll n)
{
    if(n<2) return 0;
    if(n==2) return 1;
    else
    {
        for(int i=2; i*i<=n; i++)
            if(n%i==0) return 0;
    }
    return 1;
}*/

ll countSum(ll x)
{
    ll res = 0;
    while (x != 0)
    {
        res += (x % 10);
        x /= 10;
    }
    return res;
}
int used[1111111];
int main()
{
    fast ;
    int n;
    cin >> n;
    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            if (i * j == n)
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

}



Measured memory_bytes: 3680
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;i++)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;



class UnionFind {
public:
	vector<int> r,p;

	UnionFind(){}
	UnionFind(int size) {
		r.resize(size, 0);
		p.resize(size, 0);
		rep(i, 0, size)makeSet(i);
	}

	void makeSet(int x) {
		p[x] = x;
		r[x] = 0;
	}

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

	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	void link(int x,int y) {
		if (r[x] > r[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (x == y) {
				r[y]++;
			}
		}
	}


	int findSet(int x) {
		if (x == p[x]) {
			return x;
		}
		else {
			return p[x] = findSet(p[x]);
		}
	}
};




int main(){
	int n, q;
	cin >> n >> q;

	UnionFind un = UnionFind(n);

	int query,x,y;
	rep(i, 0, q) {
		cin >> query >> x >> y;
		if (query) {
			cout << un.same(x, y) << endl;
		}
		else {
			un.unite(x, y);
		}
	}
	
	
	return 0;
}



Measured memory_bytes: 3240
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void) {
    int a, b;

    if(scanf("%d %d", &a, &b) == 1);

    if(a >= b + 1) {
        printf("%d", a + a - 1);
    } else if(b >= a + 1) {
        printf("%d", b + b - 1);
    } else {
        printf("%d", a + b);
    }

      return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    ll n,k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    ll right = 0;
    ll all = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1 ;j < n; j ++){
            if(v[i] > v[j]) right++;
        }
        for(int j = 0; j < n ; j ++){
            if(v[i] > v[j]) all++;
        }
        /*
        ans += right * k % MOD;
        ans += k*(k-1)/2 %MOD * all % MOD;
        ans %= MOD;*/
    }
    ans += right * k % MOD;
    ans += k*(k-1)/2 %MOD * all % MOD;
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime> 
#include <memory.h>
#include <assert.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18 + 1;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    for(int i = 0; i < H; i++) {
        cin >> s[i];
    }

    vector<vector<int>> r_lenv;
    for(auto hs : s) {
        int cnt = 0;
        char prev = hs[0];
        vector<int> v;
        for(int i = 0; i < hs.size(); i++) {
            if(hs[i] != prev) v.push_back(cnt), cnt = 0;
            cnt++;
            prev = hs[i];
        }
        v.push_back(cnt);
        r_lenv.push_back(v);
    }

    vector<vector<int>> r_fd(H, vector<int>(W , 0));
    for(int i = 0; i < H; i++) {
        int index = 0;
        char prev = s[i][0];
        for(int j = 0; j < W; j++) {
            if (prev != s[i][j]) index++;
            if(s[i][j] == '.') r_fd[i][j] = r_lenv[i][index];
            prev = s[i][j];
        }
    }

    vector<vector<int>> c_lenv;
    for(int i = 0; i < W; i++) {
        int cnt = 0;
        char prev = s[0][i];
        vector<int> v;
        for(int j = 0; j < H; j++) {
            if(s[j][i] != prev) v.push_back(cnt), cnt = 0;
            cnt++;
            prev = s[j][i];
        }
        v.push_back(cnt);
        c_lenv.push_back(v);
    }

    vector<vector<int>> c_fd(H, vector<int>(W, 0));
    for(int i = 0; i < W; i++) {
        int index = 0;
        char prev = s[0][i];
        for(int j = 0; j < H; j++) {
            if (prev != s[j][i]) index++;
            if(s[j][i] == '.') c_fd[j][i] = c_lenv[i][index];
            prev = s[j][i];
        }
    }

    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            ans = max(ans, r_fd[i][j] + c_fd[i][j] - 1);
        }
    }

    cout << ans << endl;

    // for(auto h : c_fd) {
    //     for(auto e : h) {
    //         cout << e << " ";
    //     }
    //     cout << endl;
    // }

    return 0;
}

Measured memory_bytes: 50048
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
int gcd(int a,int b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    int g = gcd(A,B);
    if(C%g == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()) )
n = -1
COND = True


while COND ==True:
    n += 1
    for i in range(N):
        if A[i] %2 == 0:
            A[i] = A[i] / 2
            continue
        else:
            COND = False
            break
    

print(n)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdio>
#include <stdlib.h>
using namespace std;

struct node{
	int key;
	node *parent, *left, *right;
};

node *root, *NIL;

void insert(int k){
	node *x, *y, *z;

	x = root;
	y = NIL;
	z = (node *)malloc(sizeof(node));

	z->key = k;
	z->left =NIL;
	z->right = NIL;

	while(x!=NIL){
		y = x;
		if(k<x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}

	if(y==NIL){
		root = z;
	}else{
		z->parent = y;
		if(y->key<k) y->right = z;
		else y->left = z;
	}
}

node *find(int x){
	node *z = root;
	while(z!=NIL && z->key!=x){
		if(x<z->key) z = z->left;
		else z = z->right;
	}
	return z;
}

void inorder(node *z){
	if(z==NIL) return;
	inorder(z->left);
	cout<<" "<<z->key;
	inorder(z->right);
}

void preorder(node *z){
	if(z==NIL) return;
	cout<<" "<<z->key;
	preorder(z->left);
	preorder(z->right);
}

int main(){
	int n, tem;
	string a;
	cin>>n;

	while(cin>>a){
		if(a == "insert"){
			cin>>tem;
			insert(tem);
		}
		if(a == "find"){
			cin>>tem;
			if(find(tem)!=NIL) cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
		if(a == "print"){
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}
	}
}


Measured memory_bytes: 21892
N = int(input())

F = [0]*(N+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            c = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if (c <= N):
                F[c] += 1
print(*F[1:], sep='\n')

Measured memory_bytes: 9204
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    char a;
    cin >> a;

    if ('A'<=a && a<='Z')
        cout << 'A' << endl;
    else if ('a'<=a && a<='z')
        cout << 'a' << endl;

    return 0;
}


Measured memory_bytes: 3648
a, b = map(int, input().split())
y = []
p = 0

for i in range(1, 1000):
    p += i
    y.append(p)
    
c = b - a
for i in range(1, 999):
    if y[i] - y[i - 1] == c:
        print(y[i] - b)
        break

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

int main() {
    int A, B;
    cin >> A >> B;
    int max = 0;
    int sum = A + B;
    int dif = A - B;
    int pro = A * B;
    cout << std::max(sum, std::max(dif, pro)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    long long int n;
    while(scanf("%lld",&n)!=EOF)
    {
        int f;
        f=n;
        int sum=0,m;
        while(n)
        {
            m=n%10;
            sum=sum+m;
            n=n/10;
        }
        if(f%sum==0)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

int main() {
    
	string a, b;
	cin >> a >> b;
	if (a.size() != b.size()) {
		if (a.size() > b.size()) cout << "GREATER" << endl;
		else cout << "LESS" << endl;
	}
	else {
		for (int i=0; i<a.size(); i++) {
			if (a[i] < b[i]) {
				cout << "LESS" << endl;
				exit(0);
			}
			else if (a[i] > b[i]) {
				cout << "GREATER" << endl;
				exit(0);
			}
		}
		cout << "EQUAL" << endl;
	}
	
    
}


Measured memory_bytes: 256
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> key;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int s = 0;
    rep(j, b) {
      int c;
      cin >> c;
      --c;
      s |= 1<<c;
    }
    key.emplace_back(s, a);
  }

  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  rep(i, m) {
    rep(s, 1<<n) {
      int t = s | key[i].first;
      int cost = dp[s] + key[i].second;
      dp[t] = min(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int N=Integer.parseInt(sc.next());
int S=0,temp=N;
int a=String.valueOf(N).length();
for(int i=0;i<a;i++){
S+=temp%10;
temp/=10;
}
if(N%S==0){System.out.println("Yes");}else{System.out.println("No");}
}
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

struct edge {
    ll to, cost;
};
typedef pair<ll, ll> P;
vector<vector<edge>> G;
vector<ll> d;

const ll inf = 1LL << 60;

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

    ll N, M;
    cin >> N >> M;
    G.assign(N, vector<edge>());
    d.assign(N, inf);
    d[0] = 0;
    Rep (i, N-1) {
        edge e = {i, 0};
        G[i+1].push_back(e);
    }
    while (M--) {
        ll L, R, C;
        cin >> L >> R >> C;
        L--; R--;
        G[L].push_back(edge{R, C});
    }

    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, 0));
    while (que.size()) {
        P p = que.top(); que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;
        for (auto e : G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    
    if (d[N-1] == inf) cout << -1 << "\n";
    else cout << d[N-1] << "\n";
}

Measured memory_bytes: 10108
// Problem Code: abc177_a

#include <bits/stdc++.h>

using namespace std;

string A(int D, int T, int S) {
	int x = (D + S - 1) / S;
	return (x <= T) ? "Yes" : "No";
}

int main() {
	int D, T, S;
	cin >> D >> T >> S;
	cout << A(D, T, S);
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;
    int co=1;
    rip(i,n-1,0){
        if(s[i]!=s[i+1]){
            co++;
        }
    }
    co=max(co-k*2,1);
    cout << n-co << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	private static final int AMARI = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long trainingAfter = 1;

		for (int i = 1; i <= N; i++) {
			trainingAfter *= i;
			trainingAfter = trainingAfter % AMARI;
		}
		System.out.println(trainingAfter % AMARI);
	}
}


Measured memory_bytes: 22996
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 10000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,t,ind,mn=inf,cev1;
lo cev;
string s;
vector<lo> v;

int main(void){
	scanf("%lld %lld",&n,&m);
	FOR{
		a[i]=m+i-1;
		cev+=a[i];
		if(abs(a[i]-0)<mn){mn=abs(a[i]-0);ind=i;}
	}
	FOR{
		if(i==ind)continue;
		cev1+=a[i];
	}
	printf("%lld\n",cev1);
	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
using namespace std;
using ll = long long;

int main()
{
    vector<char> num(4);
    for (int i = 0; i < 4; i++) cin >> num[i];
    int A = num[0] - '0'; int B = num[1] - '0'; int C = num[2] - '0'; int D = num[3] - '0';
    if (A + B + C + D == 7)cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
    else if (A + B + C - D == 7)cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
    else if (A + B - C + D == 7)cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
    else if (A + B - C - D == 7)cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
    else if (A - B + C + D == 7)cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
    else if (A - B + C - D == 7)cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
    else if (A - B - C + D == 7)cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
    else if (A - B - C - D == 7)cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> X(N),Y(N);
  for(int i=0;i<N;i++){
    cin>>X.at(i);
    Y.at(i)=X.at(i);
  }
  sort(Y.begin(),Y.end());
  if(Y.at(N/2-1)==Y.at(N/2)){
    for(int i=0;i<N;i++){
      cout<<Y.at(N/2-1)<<endl;
    }
  }else{
    for(int i=0;i<N;i++){
      if(X.at(i)>=Y.at(N/2)){
        cout<<Y.at(N/2-1)<<endl;
      }else{
        cout<<Y.at(N/2)<<endl;
      }
    }
  }
  
  
}

Measured memory_bytes: 3712
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    string z(b, a + '0');
    string y(a, b + '0');
    cout << min(z,y) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		while(true){	    
			int x = in.nextInt();	
			int y = in.nextInt();
			if ((x == 0 && y ==0)) {
				break;
			}
			else if (x<y){
				System.out.println(x+" "+y);
			}
			else if (x>=y){
				System.out.println(y+" "+x);
			}
		}	
	}
}

Measured memory_bytes: 27152
#include<bits/stdc++.h>
 using namespace std;
bool dp[110][50011];
long long int charge[110][50011];
int p[100];
int n; 
int main(){
  while(1){
  cin>>n;
  if(n==0){
     break;
  }
  for(int i=0;i<n;i++){
      cin>>p[i];
  }
  for(int i=0;i<110;i++){
      for(int j=0;j<50011;j++){
          dp[i][j]=false;
          charge[i][j]=5000000000;
      }
  }
  dp[0][0]=true;
  charge[0][0]=0;
  for(int i=0;i<n;i++){
      for(int j=i+1;j>=0;j--){
          for(int k=50000;k>=0;k--){
              if(dp[j][k]==false){
                  continue;
              }
              //?????£???????¨????
              int res=1000-(p[i]%1000);
              int res2=p[i]%1000;
              //i?????????????????§??????
              if(res2==0){
                 if(k>=500){
                       dp[j+1][k-500]=true;
                       if(charge[j+1][k-500]>charge[j][k]+p[i]){
                          charge[j+1][k-500]=charge[j][k]+p[i];
                       }
                 }
                 continue;
              }

              if(res2<=500){
                  dp[j+1][k+500-res2]=true;
                  if(charge[j+1][k+500-res2]>charge[j][k]+p[i]){
                     charge[j+1][k+500-res2]=charge[j][k]+p[i];
                  }
              }else{

                  if((k-(res2-500))>=0){
                     dp[j+1][k-(res2-500)]=true;
                     if(charge[j+1][k-(res2-500)]>charge[j][k]+p[i]){
                        charge[j+1][k-(res2-500)]=charge[j][k]+p[i];
                     }
                  }else{
                     dp[j][k+res]=true;
                     if(charge[j][k+res]>charge[j][k]+p[i]){
                        charge[j][k+res]=charge[j][k]+p[i];
                     }
                  }

              }
          }
      }
  }


  int ans=0;
  long long int ans2=5000000;
/*
for(int i=0;i<100;i++){
   for(int j=0;j<5000;j++){
   if(dp[i][j]==true){
      //cout<<"i"<<i<<"j"<<j<<endl;
   }
   }
}
*/

  bool check=false;
  for(int i=n;i>=0;i--){
      for(int j=0;j<50001;j++){
          if(dp[i][j]==true){

               check=true;
               ans=i;
               if(ans2>charge[i][j]){
                  ans2=charge[i][j];
               }
          }
      }
      if(check==true){
          break;
      }
  }

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

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < (int) s.size() - 1; i++) {
		if (s[i] == s[i + 1]) {
			cout << "Bad\n";
			return 0;
		}
	}
	cout << "Good\n";
}


Measured memory_bytes: 3604
N, Y = map(int, input().split())

for x in range(N+1):
    for y in range(N+1):
        z = N - x - y
        if 0 <= z <= N and 10000*x+5000*y+1000*z == Y :
            print("{} {} {}".format(x,y,z))
            exit()
print("{} {} {}".format(-1,-1,-1))


Measured memory_bytes: 2940
#104
s=input()
if s[0]!="A":
    print("WA")
elif "C" not in s[2:-1] or s[2:-1].count("C")!=1:
    print("WA")
elif s[1]==str.upper(s[1]):
    print("WA")
elif (s[1:2]+s[-1]).strip("C")==str.lower((s[1:2]+s[-1]).strip("C")):
    print("AC")
else:
    print("WA")

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

const int mod = 10007;

int main(){
	int n;
	string s;
	
	cin >> n >> s;
	
	int dp[1001][8] = {};
	dp[0][4] = 1;
	
	for(int i = 0; i < n; i++){
		for(int j = 1; j < 8; j++){
			int f = 1;
			if(s[i] == 'O') f <<= 1;
			if(s[i] == 'J') f <<= 2;
			for(int k = 1; k < 8; k++){
				if( (j&k) == 0 || (k&f) == 0) continue;
				dp[i+1][k] = (dp[i+1][k]+dp[i][j])%mod;
			}
		}
	}
	
	int ans = 0;
	for(int k = 1; k < 8; k++){
		ans = (ans + dp[n][k])%mod;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int n,_n;
pii a[200005];
ll tree[200005<<2];
void update(int ind,int val){
    ind+=_n-1;
    tree[ind]+=(ll)val;
    while(ind>1){
        ind/=2;
        tree[ind]=tree[ind*2]+tree[ind*2+1];
    }
}
ll query(int l,int r,int nl,int nr,int ind){
    if(l<=nl && nr<=r) return tree[ind];
    if(l>nr || r<nl) return 0;
    int mid=(nl+nr)>>1;
    return query(l,r,nl,mid,ind*2)+query(l,r,mid+1,nr,ind*2+1);
}
int main(){
    scanf("%d",&n);
    _n=512;
    for(int i=1;i<=n;i++){
        long double now=0;
        scanf("%Lf",&now);
        now*=(long double)1e9;
        a[i].fi+=9,a[i].se+=9;
        ll ha=round(now);
        while(ha%2==0) ha/=2,a[i].fi--;
        while(ha%5==0) ha/=5,a[i].se--;
    }
    sort(a+1,a+n+1);
    int now=1;
    ll ans=0;
    for(int i=n;i>=1;i--){
        while(now<=n && a[now].fi<=-a[i].fi)
            update(a[now].se+200,1),now++;
        ans+=query(1,-a[i].se+200,1,_n,1);
    }
    for(int i=1;i<=n;i++)
        if(a[i].fi<=0 && a[i].se<=0)
            ans--;
    printf("%lld\n",ans/2);
    return 0;
}

Measured memory_bytes: 5348
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

S = INT()

def make_divisors(n):  #約数列挙
    for i in range(ceil(n**0.5), 0, -1):
    	if n%i == 0:
    		if i <= 10**9 and n//i <= 10**9:
    			return i, n//i
	
a = ceil(S**0.5)
b = ceil(S**0.5)

if a*b == S:
	c = d = 0
else:
	c, d = make_divisors(a*b-S)

print(0, 0, a, c, d, b)

Measured memory_bytes: 10508
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
	string n;
	int a,m;
	cin>>n;
	a=n.size();
	for(int i=0;i<a;i++)
	{
		if(n[i]=='C')
		{
			for(int k=i+1;k<=a-1;k++)
			{
				if(n[k]=='F')
				{
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	n := scanInt(sc)
	ls := nextIntSlice(sc, n)
	num := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				li := ls[i]
				lj := ls[j]
				lk := ls[k]
				es := []int{li, lj, lk}
				sort.Sort(sort.IntSlice(es))
				if es[0] == es[1] || es[1] == es[2] {
					continue
				}
				if es[2] < es[0]+es[1] {
					num++
				}
			}
		}
	}
	return num
}

// package: gocom
// packed src of [/Users/masumi/dev/src/github.com/masu-mi/gamemo/lib/gocom/next.go] with goone.

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 6204
import * as fs from 'fs';

namespace AtCoder.abc090 {

    export class Program {

        constructor(private readonly args: string[]) {
        }

        /**
         * in
         * ant
         * obe
         * rec
         * out
         * abc
         */
        main(this: Program): void {

            const c123: string[] = this.args[0].split('');
            const c456: string[] = this.args[1].split('');
            const c789: string[] = this.args[2].split('');

            console.log(`${c123[0]}${c456[1]}${c789[2]}`);
        }
    }
}
 
const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg: AtCoder.abc090.Program = new AtCoder.abc090.Program(args);
prg.main();


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

using namespace std;
// #define int long long
mt19937 rnd(time(0));
typedef long long ll;
typedef long double ld;

// #define _GLIBCXX_DEBUG
#define f first
#define s second
#define pb push_back
#define pii pair<int, int> 
#define vi vector<int>

void solve(){
	int n;
	cin >> n;
	int k;
	cin >> k;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		ans += (k <= x);
	}
	cout << ans << endl;
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A, B, C, D, X, Y;
    scanf("%d%d%d%d",&A, &B, &C, &D);
    if(A>B){X=B;}
       else{
        X = A;
    }
    if (C>D){Y=D;}
        else {
        Y = C;
    }
    printf("%d\n", (X+Y) );

    return 0;

}


Measured memory_bytes: 1728
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm>
#include <utility>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i, s, n) for(int i=(s); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
#define mkp make_pair

#define INF 0x3f3f3f3f
using namespace std;

int N;
vector <int> G[102];
int far[102];

void slv()
{
   queue <int> que;
   que.push(1);
   memset( far, INF, sizeof(far) );
   far[1] = 0;

   while(!que.empty()){
      const int u = que.front();
      que.pop();
      rep(i, G[u].size()){
         const int next = G[u][i];
         if(far[u] + 1 < far[next]){
            far[next] = far[u] + 1;
            que.push( next );
         }
      }
   }

   reps(i, 1, N){
      cout << i <<  ' ' << ( far[i] == INF ? -1 : far[i] ) << '\n';
   }
   return;
}

signed main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   cin >> N;

   reps(i, 1, N){
      int u, k, a;
      cin >> u >> k;
      while(k--){
         cin >> a;
         G[u].push_back(a);
      }
   }

   slv();
   return (0);
}




Measured memory_bytes: 3184
n = int(input())
D = {}
for i in range(n):
	x = input()
	if x not in D:
		D[x] = 1
	else:
		D[x] += 1
m = int(input())
for i in range(m):
	x = input()
	if x in D:
		D[x] -= 1
print(max(0, max(D.values())))

Measured memory_bytes: 38256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long a = n/k;

        if (k%2==1){
            System.out.println(a*a*a);
        }else {
            long b = (n+k/2)/k;
            System.out.println(a*a*a+b*b*b);
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    unordered_map<string, int> m;
    m["SUN"] = 7;
    m["MON"] = 6;
    m["TUE"] = 5;
    m["WED"] = 4;
    m["THU"] = 3;
    m["FRI"] = 2;
    m["SAT"] = 1;

    auto it = m.find(S);
    cout << it->second << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{ char a,b;
  while((scanf("%c %c",&a,&b))==2)
   {  if(a=='H')
        { if(b=='H') printf("H\n");
          else printf("D\n");
		}
	  else 
	     { if(b=='H') printf("D\n");
	       else printf("H\n");
		 }
   }
   return 0;
 } 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,k;
    cin>>m>>k;
    if(k>=pow(2,m))
        cout<<-1;
    else
    {
        int i;
        if(m==1 && k==1)
            cout<<-1;
        else if(m==0)
            cout<<0<<' '<<0;
        else if(k==0)
            for(i=0;i!=pow(2,m);i++)
                cout<<i<<' '<<i<<' ';
        else
        {
            cout<<0<<' '<<k<<' '<<0<<' ';
            for(i=pow(2,m)-1;i>=1;i--)
                if(i!=k)
                    cout<<i<<' ';
            cout<<k<<' ';
            for(i=1;i!=pow(2,m);i++)
                if(i!=k)
                    cout<<i<<' ';
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from fractions import gcd

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

def calc(x,line):
    if line == 0:
        for l in v[x]:
            if e[l][0] == x: son = e[l][1]
            else: son = e[l][0]
            if a[son-1] < a[x-1] and calc(son,l) == -1:
                return 1
        return -1
    else:
        if e[line][0] == x: y = 0
        else: y = 1
        if f[line][y] != 0: return f[line][y]
        for l in v[x]:
            if l != line:
                if e[l][0] == x: son = e[l][1]
                else: son = e[l][0]
                if a[son-1] < a[x-1] and calc(son,l) == -1:
                    f[line][y] = 1
                    return 1
        f[line][y] = -1
        return -1

n = int(input())
v = [set([]) for i in range(0,n+1)]
e = [0 for i in range(0,n)]
a = readln()
for i in range(1,n):
    s = readln()
    v[s[0]].add(i)
    v[s[1]].add(i)
    e[i] = s

f = [[0,0] for i in range(0,n)]
ans = []
for i in range(1,n+1):
    if calc(i,0) == 1:
        ans.append(i)
ans = list(map(str,ans))
print(' '.join(ans))


Measured memory_bytes: 7252
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  links = {}
  for i in range(N-1):
    u, v, w = readInts()
    if not u in links:
      links[u] = {}
    if not v in links:
      links[v] = {}
    links[u][v] = w
    links[v][u] = w

  colors = [None for _ in range(N)]

  nodes = [(1, False)]
  while len(nodes) > 0:
    v, color = nodes.pop()
    colors[v - 1] = '1' if color else '0'

    for u, w in links[v].items():
      if colors[u - 1]: continue
      if w % 2 == 0:
        nodes.append((u, color))
      else:
        nodes.append((u, not(color)))
  for n in range(N):
    print(colors[n])

if __name__ == "__main__":
  main()


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

int main(){
  int n;
  ll a[200000];
  cin>>n;
  for (int i(0);i<n;i++) cin>>a[i];
  ll sum(0);
  for (int i(0);i<n;i++) sum+=a[i];
  ll mini(1e18);
  ll sumi(0);
  for (int i(0);i<n-1;i++){
    sumi+=a[i];
    cerr<<abs(sumi-(sum-sumi))<<" ";
    mini=min(mini,abs(sumi-(sum-sumi)));
  }
  cout << mini << endl;
  return 0;
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

using namespace std;

ll inf=1e18;
ll mod=(ll)10e9+7;
double pi=3.1415926535897932384626433832795;
ll i, j;
ll N=1e5;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    ll a, b, c, i, j;
    cin>>a>>b>>c;
    vector < ll > v;
//            ll n=a, m=b;
//            for(i = 1; i<=b; i++)
//            {   n=a*i; m=b-i;
//                while(1)
//                {
//                    if(n+m>=a*b) {break;}
//                    cout<<n+m<<endl;
//                    v.pb(n+m);
//                    m+=m;
//                }
//            }
//            for( i=0; i<v.size(); i++)
//            {
//                cout<<v[i]<<" ";
//            }
        for(i=0; i<=a; i++)
        {
            for(j=0; j<=b; j++)
            {
                //cout<<(a*j-i)+(b*i-j)<<endl;
                v.pb((a*j)+(b*i)-(i*j)-(i*j));
                v.pb(a*j);
                v.pb(b*i);
            }
        }

            for( i=0; i<v.size(); i++)
            {
                //cout<<v[i]<<" ";
                if(c==v[i]) {cout<<"Yes"<<endl; return 0;}
            }

/*    if(c==0)
    {
        cout<<"Yes"<<endl; return 0;
    }
    if(c==1)
    {
        if(a==1 or b==1)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        return 0;
    }
    if(a%c==0 or b%c==0 or c%a==0 or b%c==0)
    {
        cout<<"Yes"<<endl; return 0;
    }
    else
    {
        if(a*b%2==1 or a*b%2==0)
        {
            if(c==a*b/2 or c==a*b/2+1)
            {
                cout<<"Yes"<<endl; return 0;
            }
            else
            {
                cout<<"No"<<endl; return 0;
            }
        }
        else
        {

            cout<<"No"<<endl; return 0;
        }
    }*/
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 34916
// D - Road to Millionaire
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

int main(){
	int N; cin>>N;
	vector<int> A(N+1, 0);
	rp(i, 1, N+1) cin>>A[i];
	vector<ll> dp_stock(N+1, 0);
	vector<ll> dp_yen(N+1, 0);
	dp_yen[0] = 1000;
	rp(day, 1, N+1){
		dp_stock[day] = max(dp_stock[day-1], dp_yen[day-1]/A[day]);
		ll remain = dp_yen[day-1] - dp_stock[day-1]*A[day-1];
		dp_yen[day] = max(dp_yen[day-1], remain + dp_stock[day-1] * A[day]);
	}
	cout<< dp_yen[N] <<endl;
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
"""
Created on Sat May 26 21:45:21 2018

@author: sakas
"""
N = int(input())
S = input()
arr = set()
ray = set()
s = list(S)
j = 0
for i in range(len(s)):
   arr = set(list(S[:int(i)]))
   ray = set(list(S[int(i):]))
   if j < int(len(arr & ray)):
       j = len(arr & ray)
print(j)

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

const int N=110;
int a[N],n,m;
int oddnum[2];

int main()
{
    int odd=0,tot=0;
    scanf("%d%d",&n,&m);
    oddnum[0]=1;oddnum[1]=m;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",a+i);
        if(~a[i]&1) continue;
        oddnum[odd++]=i;
        if(odd>2) return puts("Impossible"),0;
    }
    swap(a[1],a[oddnum[0]]);
    swap(a[m],a[oddnum[1]]);
    if(m==1&&a[1]==1) return puts("1\n1\n1"),0;
    for(int i=1;i<=m;i++) printf("%d ",a[i]);
    if(m==1) return printf("\n2\n%d 1\n",a[1]-1),0;
    printf("\n%d\n%d ",a[m]>1?m:m-1,a[1]+1);
    for(int i=2;i<m;i++) printf("%d ",a[i]);
    if(a[m]>1) printf("%d\n",a[m]-1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;
using P3 = pair<ll, P>;
using PP = pair<P ,P>;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e6) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

const double PI = acos(-1);
 
int main(){
    double a, b, x;
    cin >> a >> b >> x;
    if(x > a*a*b/2){
        double l = (2*x)/(a*a) - b;
        double ans = atan(a/(b-l))/PI*180;
        printf("%.10lf\n", 90.0-ans);
    }
    else{
        double l = 2*x/(a*b);
        double ans = atan(l/b)/PI*180;
        printf("%.10lf\n",90.0-ans);
    }
    return 0;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
 	public static void main(String[] args) {
 		Scanner scanner = new Scanner(System.in);
 		int N = scanner.nextInt();
 		int A[] = new int[N];
 		int count = 0;
  		for (int i = 0; i < N; i++) {
  			int x = scanner.nextInt();
  			A[i] = x;
  		}
  		Arrays.sort(A);

  		for (int i = 0; i < N - 1; i++) {
  			if (A[i] == A[i + 1]) {
  				count += 1;
  				break;
  			}
  		}
  		if (count == 1) {
  			System.out.println("NO");
  		} else {
  			System.out.println("YES");
  		}
 	}
}


Measured memory_bytes: 64680