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

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;
int MinimumNumIncreasingSubsequences(int arr[], int n) 
{ 
    multiset<int> last; 
  
    // last element in each  increasing subsequence  
    // found so far 
    for (int i = 0; i < n; i++) { 
  
        // here our current element is arr[i] 
        multiset<int>::iterator it = last.lower_bound(arr[i]); 
  
        // iterator to the first element larger  
        // than or equal to arr[i] 
        if (it == last.begin()) 
  
            // if all the elements in last larger 
            // than or to arr[i] then insert it into last 
            last.insert(arr[i]); 
  
        else { 
            it--; 
  
            // the largest element smaller than arr[i] is the number 
            // before *it which is it-- 
            last.erase(it); // erase the largest element smaller than arr[i] 
            last.insert(arr[i]); // and replace it with arr[i] 
        } 
    } 
    return last.size(); // our answer is the size of last 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    ll i,j,n,m,k,cnt=0,ans=0,t=1;
    cin>>n;
    int a[n];
    rep(i,0,n) cin>>a[i];
    // cout<<(LongestIncreasingSubsequenceLength(a))<<endl;
    ret(MinimumNumIncreasingSubsequences(a,n))
    
    return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007

int main()
{
	FASTIO
    int h, w;
    cin >> h >> w;
    char grid[h][w];
    long long dp[h][w];
    memset(dp, -1, sizeof(dp));
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            cin >> grid[i][j];
            if(grid[i][j] == '#')
                dp[i][j] = 0;
        }
    }
    int pos = 0;
    while(pos < w && dp[0][pos] != 0)
    {
        dp[0][pos] = 1;
        pos++;
    }
    while(pos < w)
    {
        dp[0][pos] = 0;
        pos++;
    }
    pos = 1;
    while(pos < h && dp[pos][0] != 0)
    {
        dp[pos][0] = 1;
        pos++;
    }
    while(pos < h)
    {
        dp[pos][0] = 0;
        pos++;
    }
    for(int i=1; i<h; i++)
    {
        for(int j=1; j<w; j++)
        {
            if(dp[i][j] != 0)
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
        }
    }
    cout << dp[h-1][w-1]%MOD << "\n";
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define w(t) ll t;cin>>t; while(t--)

int main()
{
  ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s,t;cin>>s>>t;
int c=0,i;
for (i=0;i<s. length ();i++)
{
  
  if (s[i]!=t[i])
  c++;
  
}
cout<<c;

}

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

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

    auto pal = [](string A){
        string B = A;
        reverse(B.begin(), B.end());
        return A == B;
    };

    int N = S.size();
    bool ok = pal(S) && pal(S.substr(0, (N-1)/2)) && pal(S.substr((N+1)/2, N));
    cout << (ok ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
	int n, w;
	cin >> n >> w;
	int nums[n][2];
	for(int i = 0; i < n; i++){
		cin >> nums[i][0] >> nums[i][1];
	}
	long long dp[w + 1];
	for(int i = 0; i < w + 1; i++){
		dp[i] = -1;
	}
	dp[0] = 0;
	long long best = 0;
	for(int i = 0; i < n; i++){
		for(int j = w; j >= 0; j--){
			//cout << dp[i] << endl;
			if(dp[j] > -1 && j + nums[i][0] <= w){
				dp[j+nums[i][0]] = max(dp[j+nums[i][0]], dp[j] + nums[i][1]);
				best = max(best, dp[j + nums[i][0]]);
			}
		}
	}
	cout << best << endl;
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a = b = c = 0
n = int(input())
A,B = map(int,input().split())
P = list(map(int,input().split()))
for i,pi in enumerate(P):
    if pi <= A:
        a += 1
    elif A+1 <= pi <= B:
        b += 1
    else:
        c += 1
print(min(a,b,c))


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

int main() {
  int a,b;
  cin >> a >> b;
  if(abs(b-a)%2) cout << "IMPOSSIBLE" << endl;
  else cout << a+(b-a)/2 <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
#define int long long
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

struct UnionFind {
    vector<int> par;

    UnionFind (int n) : par (n, -1) {} //親は-1

    int root (int x) {
        if (par[x] < 0) return x; //自身が親
        else
            return par[x] = root (par[x]); //再帰
    }

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

    void merge (int x, int y) {
        x = root (x);
        y = root (y);
        if (x == y) return; //既に同じ根
        // xとyのサイズの大きいほうにまとめたい
        if (size (x) < size (y)) swap (x, y);
        par[x] += par[y]; //根のparは-(要素数)になる
        par[y] = x;       //親を更新
        return;
    }

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

signed main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    rep (i, 0, m) {
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }
    int ans = 0;
    rep (i, 0, m) {
        UnionFind tree (n);
        rep (j, 0, m) {
            if (i == j) continue;
            tree.merge (a[j], b[j]);
        }
        int cnt = 0;
        rep (i, 0, n) {
            if (tree.root (i) == i) cnt++;
        }
        if (cnt > 1) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3564
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n, d;
	while (cin>>n>>d,n) {
		vvi miss(n);
		vi sum(n, 0);
		REP(i, n) {
			int cn;
			cin >> cn;
			REP(j, cn) {
				int a;
				cin >> a;
				miss[i].push_back(a);
				sum[i] += a;
			}
		}
		bool clear = true;
		int ma4 = 0;
		int mi4 = 1e9;
		REP(i, n) {
			ma4 = max(ma4, sum[i]);
			mi4 = min(mi4, sum[i]);
		}
		if (ma4 - mi4 > d) {
			clear = false;
			break;
		}
		
		while (1) {
			int ma = 0;
			int ma2 = 0;
			int maidx;
			REP(i, sum.size()) {
				if (sum[i] == 0)
					goto res;
				if (ma < sum[i]) {
					ma = sum[i];
					ma2 = miss[i][miss[i].size()-1];
					maidx = i;
				}
				if (ma == sum[i]) {
					if (ma2 < miss[i][miss[i].size() - 1]) {
						ma = sum[i];
						ma2 = miss[i][miss[i].size() - 1];
						maidx = i;
					}
				}
			}
			REP(i,n) {
				if (i == maidx)
					continue;
				while (sum[i] - miss[i][miss[i].size() - 1] >= ma - d) {
					sum[i] -= miss[i][miss[i].size() - 1];
					miss[i].erase(miss[i].end()-1);
					if (sum[i] == 0)
						goto res;
				}
			}
			sum[maidx] -= miss[maidx][miss[maidx].size() - 1];
			miss[maidx].erase(miss[maidx].end()-1);
			int ma3 = 0;
			int mi3 = 1e9;
			REP(i,n) {
				ma3 = max(ma3, sum[i]);
				mi3 = min(mi3, sum[i]);
			}
			if (ma3 - mi3 > d) {
				clear = false;
				break;
			}
		}
		res:
		if (clear)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
}

Measured memory_bytes: 3100
#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 EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long ll;

using namespace std;

int main(){

	int sum=0;
	int n;
	cin >> n;
	int t[100]={0};
	REP(i,n){
		cin >> t[i];
	}
	int m;
	cin >> m;
	int p,x;
	REP(i,m){
		sum = 0;
		cin >> p >> x;
		REP(j,n){
			if(p==j+1)sum += x;
			else sum += t[j];
		}
		cout << sum << endl;
	}

    return 0;
}

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

int main() {
    int a,b,c,x;
    int count = 0;
    cin >> a >> b >> c >> x;

    for(int i = 0; i <= a; i++) {
        if(i * 500 > x) {
            break;
        }
        x -= i*500;

        for(int j=0; j <= b; j++) {
            if(j*100 > x) {
                break;
            }
            x-= j*100;

            for(int k=0; k<= c;k++) {
                if(k*50 > x){
                    break;
                }
                if(k*50 == x) {
                    count++;
                    break;
                }

            }
            x+= j*100;

        }
        x += i*500;
    

    }
    cout << count << endl;


}

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

int a[100000] = {};

int solve(int n) {
    long min = 10000000000;
    int min_id;
    for (int i = 0; i < n; i++) {
        if (a[i] < min && a[i] != 0) {
            min = a[i];
            min_id = i;
        }
    }
    for (int i = 0; i < n; i++) {
        if (i!=min_id) a[i] = a[i] % min;
    }
    min = 10000000000;
    int count_zero = 0;
    for (int i = 0; i < n; i++) {
        if (i != min_id && a[i] == 1) return 1;
        else if (a[i] == 0) count_zero++;
    }
    if (count_zero == n - 1) return a[min_id];
    else return solve(n);
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i =0; i < n; i++) {
        scanf(" %d", &a[i]);
    }
    printf("%d\n", solve(n));
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int b, c, cnt;
bool dfs(int x){
    if(x > b){
        b = x;
        return 1;
    }
    if(x > c){
        c = x;
        return 1;
    }
    return 0;
}

int main(void){
    int N, x;
    cin >> N;
    while(N != 0){
        b = 0;
        c = 0;
        cnt = 0;
        for(int i = 0; i < 10; i++){
            cin >> x;
            cnt += dfs(x);
        }
        if(cnt == 10)   cout << "YES" << endl;
        else    cout << "NO" << endl;
        N--;
    }
    return 0;
}

    




Measured memory_bytes: 2956
n = gets.to_i
count = 0
max_count = 0
max_num = 1
original_num = 0
1.upto(n) do |num|
  original_num = num
  while num.even?
    num /= 2
    count += 1
  end
  if max_count < count
    max_count = count
    max_num = original_num
  end
  count = 0
end
puts max_num

Measured memory_bytes: 1788
use std::collections::VecDeque;
use std::io::stdin;

const INF: usize = 100000000;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse::<usize>().unwrap());
    let n = itr.next().unwrap();
    let x = itr.next().unwrap() - 1;
    let y = itr.next().unwrap() - 1;

    let mut ans = vec![0; n];
    for i in 0..n {
        let mut q = VecDeque::new();
        let mut dist = vec![INF; n];
        q.push_back(i);
        dist[i] = 0;
        while !q.is_empty() {
            let v = q.pop_front().unwrap();
            let d = dist[v];
            if v > 0 && dist[v - 1] == INF {
                dist[v - 1] = d + 1;
                q.push_back(v - 1);
            }
            if v + 1 < n && dist[v + 1] == INF {
                dist[v + 1] = d + 1;
                q.push_back(v + 1);
            }

            if v == x && dist[y] == INF {
                dist[y] = d + 1;
                q.push_back(y);
            }

            if v == y && dist[x] == INF {
                dist[x] = d + 1;
                q.push_back(x);
            }
        }

        for i in 0..n {
            ans[dist[i]] += 1;
        }
    }

    for i in 1..n {
        println!("{}", ans[i] / 2);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
ll inf=1e18;
int mod=1e9+7;
int arr[22][22];
int dp[(1<<21)+1];
int n;
int fun(int mask)
{

    int cn=__builtin_popcount(mask);
    if(cn==n)
        return 1;
    if(dp[mask]!=-1)
        return dp[mask];
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(arr[cn][i]==1 && (mask&(1<<i))==0)
        {
            ans+=fun(mask|(1<<i));
            ans%=mod;
        }
    }
    return dp[mask]=ans;
}
int main()
{
//    READ;
    sf(n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            sf(arr[i][j]);
        }
    }
    mem(dp,-1);
    cout<<fun(0)<<endl;
    return 0;
}


Measured memory_bytes: 8448
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 500005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll D,C = 26;
    cin >> D;
    vector<ll> c(C),t(D);
    vector<vector<ll>> s(D,vector<ll>(C));
    cins(all(c));
    rep(i,D){
        rep(j,C){
            cin >> s[i][j];
        }
    }
    vector<ll> last(C,-1);
    cins(all(t));
    ll ans = 0;
    rep(i,D){
        ans += s[i][t[i]-1];
        last[t[i]-1] = i;
        rep(j,C){
            ans -= c[j]*(i-last[j]);
        }
        PRINT(ans);
    }
}


Measured memory_bytes: 3712
from collections import defaultdict

N, M = map(int, input().split(' '))
edges = [map(int, input().split(' ')) for _ in range(M)]

paths = defaultdict(set)

for start, end in edges:
    if start == 1:
        paths[end] |= {start, end}
    elif end == N:
        paths[start] |= {start, end}

for path in paths.values():
    if {1, N}.issubset(path):
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 108484
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int a[200000];
signed main(){
	int n;scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
	}
	if(a[0]){
		puts("-1");return 0;
	}
	ll ans=0;
	rep(i,n-1){
		if(a[i+1]>a[i]+1){
			puts("-1");return 0;
		}
		if(a[i+1]==a[i]+1){
			ans++;
		}
		else{
			ans+=a[i+1];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << endl;
  return 0;
}


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

typedef int VAL;
const int MAX_UF = 110000;
const VAL SUM_UNITY = 0;

struct UnionFind {
  int par[MAX_UF];
  int rank[MAX_UF];
  VAL diff_weight[MAX_UF];

  UnionFind(int n = 0) {
	for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }
  
  void init(int n) {
	for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
  }
  
  int root(int x) {
	if (par[x] == x) {
	  return x;
	}
	else {
	  int r = root(par[x]);
	  diff_weight[x] += diff_weight[par[x]];
	  return par[x] = r;
	}
  }

  VAL weight(int x) {
	root(x);
	return diff_weight[x];
  }
  
  bool issame(int x, int y) {
	return root(x) == root(y);
  }

  bool merge(int x, int y, VAL w) {
	w += weight(x); w -= weight(y);
	x = root(x); y = root(y);
	if (x == y) return false;
	if (rank[x] < rank[y]) swap(x, y), w = -w;
	if (rank[x] == rank[y]) ++rank[x];
	par[y] = x;
	diff_weight[y] = w;
	return true;
  }

  VAL diff(int x, int y) {
	return weight(y) - weight(x);
  }
  
} uf;



int N, M;
int main() {
  cin >> N >> M;
  uf.init(N);
  for (int i = 0; i < M; ++i) {
	int l, r, d;
	cin >> l >> r >> d;
	--l, --r;
	if (uf.issame(l, r)) {
	  int diff = uf.diff(l, r);
	  if (diff != d) {
		puts("No");
		return 0;
	  }
	}
	else {
	  uf.merge(l, r, d);
	}
  }
  puts("Yes");
}




Measured memory_bytes: 1408
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    int h = nextInt();
    int w = nextInt();
    int n = nextInt();

    int ans = 0;

    if(h>=w){
      ans = n/h;
      if(n%h!=0){
        ans ++;
      }
    }
    else{
      ans = n/w;
      if(n%w!=0){
        ans ++;
      }
    }



    System.out.println(ans);

  }
  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 21716
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
   long long int dp[n];

  for(int i=0;i<n;i++)
  {cin>>a[i];
   dp[i]=1000000000;
   }
  
  dp[0]=0;
  for(int i=1;i<n;i++)
  {
    for(int j=1;j<=k && j<=i;j++){
      dp[i]=min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]);
    }
  }
    cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
struct Query {
    int head;
    int a;
    int b;
};

int main(void)
{
    ll  min = 0;
    priority_queue<int> lQue;
    priority_queue< int, std::vector<int>, std::greater<int> > rQue;

    int head, q;
    cin >> q;
    vector<Query> query(q);
    rep(i, q){
        cin >> query[i].head;
        if(query[i].head == 1){
            cin >> query[i].a >> query[i].b;
        }
    }

    lQue.push(query[0].a);
    min += query[0].b;

    for (int i = 1; i < q; i++)
    {
        if(query[i].head == 1){
            //lQue.size() >= rQue.size() を維持し続ける
            //偶数個の場合は中央2個が最小
            if(lQue.size() == rQue.size()) {
                if(query[i].a <= lQue.top()){
                    min +=  lQue.top() - query[i].a;
                    lQue.push(query[i].a);
                }else if(rQue.top() <= query[i].a){
                    min +=  query[i].a - rQue.top();
                    rQue.push(query[i].a);
                    lQue.push(rQue.top());
                    rQue.pop();
                }else{
                    lQue.push(query[i].a);
                }
            }else{//奇数個の場合はlQue.size()のほうが大きく、このtopが最小。
                if(query[i].a <= lQue.top()){
                    min +=  lQue.top() - query[i].a;
                    lQue.push(query[i].a);
                    rQue.push(lQue.top());
                    lQue.pop();
                }else {
                    min +=  query[i].a - lQue.top();
                    rQue.push(query[i].a);
                }
            }
            min += query[i].b;
        }else{
            cout << lQue.top() << " " << min << endl;  
        }
    }
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
	int n;

	scanf("%d", &n);

	vector<int> cnt(n + 1);

	for(int i = 1; i < n; i++) for(int j = i; j < n; j += i) cnt[j]++;

	printf("%lld\n", accumulate(cnt.begin(), cnt.end(), 0LL));
}


Measured memory_bytes: 7240
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String[] tango=new String[100];
		int cnt=1;

		int kazu=sc.nextInt();

		tango[0]=sc.next();
		String tmp="";

		for(int i=1; i<kazu; i++) {
			tmp=sc.next();
			for(int j=0; j<cnt; j++) {
				if(!tmp.equals(tango[j])) {
					//
				}
				else if(tmp.equals(tango[j])) {
					System.out.println("No");
					System.exit(0);
				}
			}
			tango[cnt]=tmp;
			cnt++;
		}

		for(int i=1; i<kazu; i++) {
			if(tango[i-1].charAt(tango[i-1].length()-1)==tango[i].charAt(0)) {
				//
			}
			else if(tango[i-1].charAt(tango[i-1].length()-1)!=tango[i].charAt(0)) {
				System.out.println("No");
				System.exit(0);
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define fo(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
const int N=2e5+11;
char s[N],t[N];
int main(){
	ios::sync_with_stdio(0);
	int n,m,c;
	int sr,sc;
	cin>>n>>m>>c>>sr>>sc>>s+1>>t+1;
	int x=1,y=n,a=1,b=m;
	per(i,1,c){
		if(i<c){
			if(t[i]=='U')y=min(y+1,n);
			if(t[i]=='D')x=max(x-1,1);
			if(t[i]=='L')b=min(b+1,m);
			if(t[i]=='R')a=max(a-1,1);
		}
		if(s[i]=='U')++x;
		if(s[i]=='D')--y;
		if(s[i]=='L')++a;
		if(s[i]=='R')--b;
		if(x>y||a>b){
			puts("NO");
			return 0;
		}
		//cerr<<x<<" "<<y<<" "<<a<<" "<<b<<endl;
	}
	if(sr>y||sr<x||sc>b||sc<a){
		puts("NO");
		return 0;
	}
	puts("YES");
}

Measured memory_bytes: 640
import sys

while True:
    n = int(sys.stdin.readline().rstrip())
    if n == 0:
        break;
    dic = {}
    for i in range(n):
        k,v = sys.stdin.readline().rstrip().split(' ')
        dic[k] = v
    n = int(sys.stdin.readline().rstrip())
    ret = []
    for i in range(n):
        d = sys.stdin.readline().rstrip()
        if d in dic.keys():
            ret.append(dic[d])
        else:
            ret.append(d)
    print(''.join(ret))

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, ans = 0;
    cin >> n;
    vector<int> x(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    ans = INF;
    for(int i = 0; i <= 100; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += (i - x[j]) * (i - x[j]);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


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

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

long long lcm(long long a, long long b){
  long long g = gcd(a, b);
  return a / g * b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long res = 1LL;
  for(int i = 0; i < n; i++){
    long long t;
    cin >> t;
    res = lcm(res, t);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <sstream>
#include <map>
using namespace std;

#define index foo

map<char, int> index;
int ch_count;
int coef[11];
int as[11];
bool not_zero[11];

int pow10(int n) {
    int ret = 1;
    for (int i = 0; i < n; i++)
        ret *= 10;
    return ret;
}

bool check() {
    int sum = 0;
    for (int i = 1; i < ch_count; i++) {
        sum += as[i] * coef[i];
    }
    //if (sum == 0) {
    //    for (int i = 1; i < ch_count; i++) {
    //        cout << as[i] << ' ' << coef[i] << endl;
    //    }
    //    cout << endl;
    //}
    return sum == 0;
}

int cnt(int cur = 1, int used = 0) {
    if (cur == ch_count) return check() ? 1 : 0;
    int ret = 0;
    for (int i = 0; i < 10; i++) {
        if (i == 0 && not_zero[cur]) continue;
        if (used & (1 << i)) continue;
        as[cur] = i;
        ret += cnt(cur+1, used | (1 << i));
        as[cur] = 0;
    }
    return ret;
}

int main() {
    int n;
    while (cin >> n, n) {
        int cur = 1;
        index = map<char, int>();
        memset(coef, 0, sizeof(coef));
        memset(as, 0, sizeof(as));
        memset(not_zero, 0, sizeof(not_zero));
        for (int i = 0; i < n-1; i++) {
            string e; cin >> e;
            for (int j = 0; j < e.size(); j++) {
                if (index[e[j]] == 0) index[e[j]] = cur++;
                coef[index[e[j]]] += pow10(e.size()-1-j);
            }
            if (e.size() != 1) not_zero[index[e[0]]] = true;
        }
        string obj;
        cin >> obj;
        for (int j = 0; j < obj.size(); j++) {
            if (index[obj[j]] == 0) index[obj[j]] = cur++;
            coef[index[obj[j]]] -= pow10(obj.size()-1-j);
        }
        if (obj.size() != 1) not_zero[index[obj[0]]] = true;
        ch_count = cur;
        cout << cnt() << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int L = Integer.parseInt(sc.next());
		int R = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int x = R/d;
		int y = L/d;
		int answer=x-y;
		if(R%d==0&&L%d==0) {
			answer ++;
		}
		System.out.println(answer);

	}

}

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

using namespace std;

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

#define N 100010
#define M 200010
#define endl "\n"
#define mod 1000000007

int cnt = 0;

class Graph
{
    int V;    // No. of vertices

    // Pointer to an array containing adjacency lists
    list<int> *adj;

    // A function used by DFS
    void DFSUtil(int v, bool visited[]);
public:
    Graph(int V);   // Constructor
    ~Graph();
    void addEdge(int v, int w);
    void connectedComponents();
};

// Method to print connected components in an
// undirected graph
void Graph::connectedComponents()
{
    // Mark all the vertices as not visited
    bool *visited = new bool[V];
    for(int v = 0; v < V; v++)
        visited[v] = false;

    for (int v=0; v<V; v++)
    {
        if (visited[v] == false)
        {
            // print all reachable vertices
            // from v
            DFSUtil(v, visited);
            cnt++;

           // cout << "\n";
        }
    }
    delete[] visited;
}

void Graph::DFSUtil(int v, bool visited[])
{
    // Mark the current node as visited and print it
    visited[v] = true;
   // cout << v << " ";

    // Recur for all the vertices
    // adjacent to this vertex
    list<int>::iterator i;
    for(i = adj[v].begin(); i != adj[v].end(); ++i)
        if(!visited[*i])
            DFSUtil(*i, visited);
}

Graph::Graph(int V)
{
    this->V = V;
    adj = new list<int>[V];
}

Graph::~Graph()
{
    delete[] adj;
}

// method to add an undirected edge
void Graph::addEdge(int v, int w)
{
    adj[v].push_back(w);
    adj[w].push_back(v);
}

int main(){

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

	int n, m;

	cin >> n >> m;
	Graph g(n);

	for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;

        a--, b--;
        g.addEdge(a, b);
	}

//    Graph g(5); // 5 vertices numbered from 0 to 4
//    g.addEdge(1, 0);
//    g.addEdge(2, 3);
//    g.addEdge(3, 4);

//    cout << "Following are connected components \n";
    g.connectedComponents();

    cout << cnt - 1 << endl;

	return 0;
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int main(){
	int a,b;
	char op;
	cin >> a >> op >> b;
	switch(op){
		case '+':cout << a+b << endl;break;
		case '-':cout << a-b << endl;break;
	}
}

Measured memory_bytes: 3552
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());

		int bounce = 1;
		int height = 0;

		for (int i = 0; i < n; i++) {
			height += Integer.parseInt(sc.next());
			if(height > x) {
				break;
			}
			bounce++;
		}

		System.out.println(bounce);

	}
}

Measured memory_bytes: 23764
import math

a, b, h, m = list(map(int, input().split()))
deg_a = (60 * h + m) * (360 / (60 * 12))
deg_b = m * (360 / 60)
deg = abs(deg_a - deg_b)
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(c2 ** 0.5)

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
    int64 N;
    cin >> N;
    vector<int64> a(N);
    REP(i, N) cin >> a[i];
    multiset<int64> dp;
    REP(i, N) {
        auto st = dp.upper_bound(-a[i]);
        if (st == dp.end()) {
            dp.insert(-a[i]);
        } else {
            dp.erase(st);
            dp.insert(-a[i]);
        }
    }
    cout << dp.size() << endl;
}


Measured memory_bytes: 5760
using Yorukatsu023.Questions;
using Yorukatsu023.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu023.Questions
{
    /// <summary>
    /// ABC112 A
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadLine();
            switch (n)
            {
                case "1":
                    yield return "Hello World";
                    yield break;
                case "2":
                    var a = inputStream.ReadInt();
                    var b = inputStream.ReadInt();
                    yield return a + b;
                    yield break;
                default:
                    break;
            }
        }
    }
}


namespace Yorukatsu023
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu023.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu023.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

int main(){
 int h,w,i,j;
 
 while(1){
  cin >> h >> w;
  if(h==0&&w==0)break;
  for(i=0;i<w;i++){
   cout << "#" ;
  }
  cout << endl;
  for(i=1;i<h-1;i++){
   cout << "#" ;
   for(j=1;j<w-1;j++){
    cout << "." ;
   }
   cout << "#" << endl;
  }
  for(i=0;i<w;i++){
   cout << "#" ;
  }
  cout << endl;
 cout << endl;
 }

 return 0;
}

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

int main(void){
    int p=0;
    vector<int> x(5);
    for (int i=0; i<5; i++) {
        cin >> x[i];
    }

    for(int i=0; i<5; i++) {
        if(x[i] == 0) {
            p = i+1;
            break;
            }
    }
    cout << p << endl;

    return 0;
}


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


int main () {
  ll h, n;
  cin >> h >> n;
  vector<int> dp(h+1);
  rep(i,h+1) dp[i] = -1;
  dp[0] = 0;
  ll a[n], b[n];
  rep(i,n) {
    cin >> a[i] >> b[i];
  }
  rep(i, h+1) {
    ll tmp = 1000000000;
    rep(j, n) {
      if(a[j] >= i) { // attack is bigger than hitpoint
        tmp = min(tmp, b[j]);
      }
      else {
        tmp = min(tmp, dp[i - a[j]] + b[j]);
      }
    }
    dp[i] = tmp;
  }
  cout << dp[h] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[2000009];
int c[2000009];
int dp(int a,int b[],int c[]){
    if(c[a] != 'c'){
        return c[a];
    }
    if(a<2){
      c[a]=0;
        return 0;
    }
    else{
        c[a] = min(dp(a-2,b,c)+abs(b[a]-b[a-2]),dp(a-1,b,c)+abs(b[a]-b[a-1]));
        return c[a];
    }
}

int main(){
    int x;
    cin >> x;
    for(int i=1;i<x+1;i++){
        cin >> a[i];
      c[i]='c';
    }
    a[0] = a[1];
    cout << dp(x,a,c);



}



Measured memory_bytes: 12544
N, M = gets.split.map(&:to_i)
S = N.times.map { gets.split.map(&:to_i) }.sort_by{|v| -v[1] }
bitset = Array.new(M + 1, &:itself) # a variant of Union Find Tree.

class << bitset
  def next_clear_bit(base)
    return size if base >= size
    return base if self[base] == base
    self[base] = next_clear_bit(self[base])
  end
  
  def extend_trailling_set_bits(base)
    r = next_clear_bit(base)
    return nil if r >= size
    self[r] = r + 1
    r
  end
end

puts S.inject(0){|s, (a, b)| bitset.extend_trailling_set_bits(a) ? s + b : s }



Measured memory_bytes: 12664
n = int(input())
L=list(map(int,input().split()))
import itertools
p = list(itertools.combinations(L, 3))

cnt=0
for j in range(len(p)):
    m =p[j].index(max(p[j]))
    if len(list(set(p[j]))) ==3:
        if m==0:
            if abs(p[j][1]-p[j][2]) < p[j][m] < p[j][1]+p[j][2]:
                cnt+=1
        elif m==1:
            if abs(p[j][0]-p[j][2]) < p[j][m] < p[j][0]+p[j][2]:
                cnt+=1 
        elif m==2:
            if abs(p[j][0]-p[j][1]) < p[j][m] < p[j][0]+p[j][1]:
                cnt+=1
print(cnt)

Measured memory_bytes: 20584
N = int(input())
A = []

max_a = 0
max_i = 0
for i in range(N):
    a = int(input())
    if a > max_a:
        max_a = a
        max_i = i
    A.append(a)

del A[max_i]
max2_a = max(A)

ans_arr = []
for i in range(N):
    if max_i == i:
        ans_arr.append(str(max2_a))
    else:
        ans_arr.append(str(max_a))

ans = '\n'.join(ans_arr)
print(ans)

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

#define ll long long int
#define str string
#define sec .second

ll MOD = 1000000007,INFL = 1ll << 60,INF = 1 << 30;
ll A[10000] = {},X[1000] = {},coun[60] = {},bcou[60] = {};
pair<ll,ll> rui[100000] = {},ruin[100002] = {};
int dy[]={0, 0, 1, -1},dx[]={1, -1, 0, 0};
vector <ll> v;
ll a = 0,b = 0,c = 1,n = 0,su = 0, ma = INF,mi=-1;
pair<str,ll> S[1000];
bool an = false,bn = false;



int main(){
        cin.tie(0);
        ios::sync_with_stdio(false);
        //Code Line
cin >> n >> a;
if(n < a)cout << 0 << endl;
else cout << 10 << endl;
  //Code Line
        return 0;
}


Measured memory_bytes: 3456
import sys
import numpy as np


scan = sys.stdin.readline


def main():
    n, m = map(int, scan().rstrip().split())
    a = np.array([int(_) for _ in scan().rstrip().split()])

    votes = np.sum(a)
    candidate_num = np.sum(a >= (votes / (4 * m)))
    
    if candidate_num >= m:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 12448
#include<stdio.h>
int main(void){
    char x[1001];//1000桁+\n
    int total[99999],i,j,k;
    
    for(j=0;;j++){
        scanf("%s",x);
        if( x[0]=='0' && x[1]=='\0') break;
        for(i=0; x[i]!='\0' ;i++){
            total[j]+=x[i]-'0';
        }
    }

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

    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  if(a%2 == 0 || b%2 == 0) cout << "Even" << endl;
  else cout << "Odd" << endl;
    
  
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);

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

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

    double ans = a[0];

    for(int i = 1; i < n; ++i){
        ans = (ans + a[i]) / 2.0;
    }

    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def is_repdigit(n):
    b = True
    tmp = list(n)
    for t in tmp:
        if t != tmp[0]:
            b = False
    return b

def completion(n):
    tmp = list(n)
    if len(tmp) < 4:
        while len(tmp) != 4:
            tmp.append('0')
    return "".join(tmp)

while True:
    n = raw_input()
    if n == "0000":
        break
    i = 0
    while True:
        if n == "6174":
            print i
            break

        n = completion(n)
        if is_repdigit(n):
            print "NA"
            break

        tmp = list(n)
        tmp.sort()
        s = "".join(tmp)
        tmp.reverse()
        l = "".join(tmp)
        n = str(int(l) - int(s))
        i += 1

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

void solve() {
  int k;
  string s;
  cin >> k >> s;
  cout << ((s.size() <= k) ? s : (s.substr(0, k) + "...")) << endl;
}

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

Measured memory_bytes: 3660
#include<stdio.h>

int main(void)

{

 int a,b,c,i,j;
 int n=0;

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

 for(i=1;i<=c;i++){

 if(c%i==0){

 for(j=a;j<=b;j++){

 if(i==j){

 n++;

 }

 }

 }

 }

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

 return 0;

}

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

int main(){
  ll n,p;
  cin >> n;
  p=1000000007;
  vector<int> x(n);
  vector<int> a(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  if(a.at(0)!=0){
    cout << 0 << endl;
    return 0;
  }
  
  ll s=1;
  for(i=0;i<n;i++){
    if(x.at(a.at(i))>=3){
      s=0;
    }
    if(a.at(i)==0){
      s=(s*(3-x.at(0)))%p;
    }else{
      if(x.at(a.at(i)-1)<x.at(a.at(i))){
        s=0;
      }else{
        s=(s*(x.at(a.at(i)-1)-x.at(a.at(i))))%p;
      }
    }
    x.at(a.at(i))++;
  }
  
  cout << s << endl;
}

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

int main(){
	string moji;
	cin >> moji;
	for (int i=0; i<4; i++){
	cout << moji[i];
	}
	cout << " " ;
	
	for(int i=4; i<12; i++){
		cout << moji[i];
	}
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 256