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

int main()
{
	int n,k;
	int ans;
	cin>>n>>k;
	int i,j;
	int a[n],dp[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	dp[0]=0;dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{   
	    if(i-k<0) j=0;
	    else j=i-k;
	    ans=dp[i-1]+abs(a[i]-a[i-1]);
		for(;j<i;j++)
		ans=min(ans,abs(a[j]-a[i])+dp[j]);
		
		dp[i]=ans;
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int,input().split()))
SUM = sum(A)
def sum_half():
    cnt = 0
    for i in range(N):
        cnt += A[i]
        if cnt>SUM/2:
            return i
index = sum_half()
min_cost = 10000000000
p = sum(A[:index+1])-sum(A[index+1:])
q = sum(A[index:])-sum(A[:index])
if min_cost>p:
    min_cost = p
if min_cost>q:
    min_cost = q
print(min_cost)

Measured memory_bytes: 26024
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


X = read_a_int()
# 買うことのできる値段はXは100*N<=X<=105*Nのはず。
for n in range(1000):
    if 100 * n <= X <= 105 * n:
        print(1)
        exit()
else:
    print(0)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int a[105],b[105];

int main()
{
    int n,m,x,y;
    scanf("%d%d%d%d",&n,&m,&x,&y);
    for(int i = 0; i < n; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < m; i++)
        scanf("%d",&b[i]);
    sort(a,a+n);
    sort(b,b+m);
    /*for(int i = 0; i < n; i++)
        printf("%d ",a[i]);
        printf("\n");
    for(int i = 0; i < m; i++)
        printf("%d ",b[i]); printf("\n");*/
    int t = a[n-1]+1;
    if(t > x && t <= b[0] && t <= y)
        printf("No War\n");
    else printf("War\n");
    return 0;
}



Measured memory_bytes: 256
<?php
  
  $line = trim(fgets(STDIN));
  $lines = explode(' ', $line);
  
  $l = $lines[1] - 1;
  $list = [];
  $items = [];
  $all = 0;
  for ($i=1;$i<=$lines[0];$i++) {
    $list[] = $i + $l;
    $items[] = abs($i + $l);
    $all += $i + $l;
  }

  echo $all - $list[array_search(min($items), $items)];
  
  
?>

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 n;
string s[101010];
string t[4] = {"AC","WA", "TLE", "RE"};
int a[4];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		for(int j = 0; j < 4; j++){
			if(t[j]==s[i]) a[j]++;
		}
	}
	
	for(int i = 0; i < 4; i++){
		cout << t[i] << " x " << a[i] << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 6800
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;queue<int> q;
long long pos[100005],val[100005];
inline int fix(int x) {return max(x,-x);}
int main() {int n,s,lb,rb,bnd=0;long long ans=0;
	scanf("%d%d",&n,&s);for (int i=1;i<=n;++i) {
		scanf("%lld%lld",pos+i,val+i);if (pos[i]<s) bnd=i;
	}lb=1,rb=n;while ((lb<=bnd)^(rb<=bnd)) {
		if (val[lb]<val[rb]) q.push(pos[lb]),val[rb]+=val[lb],++lb;
		else q.push(pos[rb]),val[lb]+=val[rb],--rb;
	}if (rb<=bnd) for (int i=lb;i<=rb;++i) q.push(pos[i]);
	else for (int i=rb;i>=lb;--i) q.push(pos[i]);q.push(s);
	while (q.size()>1) lb=q.front(),q.pop(),rb=q.front(),ans+=fix(lb-rb);
	printf("%lld",ans);return 0;
}

Measured memory_bytes: 5180
import itertools
import numpy as np

N = int(input())
P = tuple(int(x) for x in input().split())
Q = tuple(int(x) for x in input().split())

A = [int(x+1) for x in range(N)]

array = list(itertools.permutations(A))

a = array.index(P)+1
b = array.index(Q)+1

print(abs(a-b))

Measured memory_bytes: 21464
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          (x).begin(),(x).end()
#define     rz(x)           resize(x)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     pii             pair<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n, x)     (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     nshow(x,n)      for(int zz=0;zz<n;++zz)cout<<x[zz]<<" ";cout<<"\n";
#define     show2(x)        for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

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

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,x,y;
    cin>>n>>x>>y;

    vector<int> cnt(n,0);
    for(int i=1;i<=n;++i)
    {
        for(int j=i+1;j<=n;++j)
        {
            int dist=j-i,a=i,b=j;

            if(x<=a)
            {
                if(y<=b)
                    dist=min(dist,a-x+b-y+1);
                else
                    dist=min(dist,a-x+y-b+1);
            }
            else if(x>a)
            {
                if(y<=b)
                    dist=min(dist,x-a+b-y+1);
                else
                    dist=min(dist,x-a+y-b+1);
            }

            ++cnt[dist];
        }
    }

    for(int i=1;i<n;++i)
        cout<<cnt[i]<<"\n";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
         
        using namespace std;
         
        constexpr long long MOD = 1000000007;
         
        long long pow_mod(long long b, long long e)
        {
        	long long res = 1;
        	for (long long i = 0; i < e; i++)
        		res = (res * b) % MOD;
        	return res;
        }
         
        int main()
        {
        	long long n;
        	cin >> n;
        	long long res = ((pow_mod(10, n) - (2ll * pow_mod(9, n)) % MOD) % MOD + pow_mod(8, n)) % MOD;
            cout << (res + MOD) % MOD << endl;
        	return 0;
        }

Measured memory_bytes: 3624
def gcd(g, s):
    while g % s != 0:
        s, g = sorted([g,s])
        g = g % s
    return s

def main():
    n, x = map(int, input().split())
    X = list(map(int, input().split()))

    for i in range(n):
        X[i] -= x
        if X[i] < 0:
            X[i] *= -1

    m = X[0]
    for c in X[1:]:
        m = gcd(c,m)

    print(m)

if __name__ == "__main__":
    main()

Measured memory_bytes: 14228
import java.util.Scanner;

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

        for(int i = 0; i < 3; i++){
            if(S.charAt(i) == S.charAt(i + 1)){
                ans = "Bad";
                break;
            }
        }
        System.out.print(ans);
    }
}

Measured memory_bytes: 23764
#include<stdio.h>
#include<bitset>
#include<iostream>
#include<set>
#include<string.h>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<math.h>
#include<string.h>

using namespace std;
  
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
 
#define pb push_back
#define ii pair<int, int> 
#define iii pair<int, ii > 
#define vai freopen("in","r",stdin);
#define inf 0x3f3f3f3f
#define f first
#define s second	

const ll INF = 1e18;
const double dinf = 12345678;       
const int mod = 1000000007;
const int maxn = 1e5 + 200;
const int MAX = 1e4 + 10;
 
 
 
int n , dp[maxn];	
int main (){
	ios_base::sync_with_stdio(false); cin.tie(nullptr);

	cin >> n;
	
	for(int i = 0 ;i < maxn;i++)dp[i] = inf;
	
	dp[n] = 0;
	for(int i  = n;i > 0 ;--i){
		for(int j = 1; j <= i; j*=6 ){
			dp[i-j]= min(dp[i-j] , dp[i] + 1);
		}
		
		for(int j = 1; j <= i; j*=9 ){
			dp[i-j]= min(dp[i-j] , dp[i] + 1);
		}
	}
		
	cout << dp[0] << '\n';
	
	return 0;
	
}


Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100009], b[100009], c[100009], p[100009], id[100009]; long long ans[100009], pot[100009]; vector<int> g[100009];
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n - 1; i++) cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, p[i] = i;
	sort(p, p + n - 1, [](int i, int j) { return c[i] > c[j]; });
	for (int i = 0; i < n; i++) id[i] = i, g[i] = { i };
	for (int i = 0; i < n - 1; i++) {
		int va = a[p[i]], vb = b[p[i]], vc = c[p[i]], ga = id[va], gb = id[vb];
		int sza = g[ga].size(), szb = g[gb].size();
		if (sza < szb) swap(sza, szb), swap(va, vb), swap(ga, gb);
		pot[ga] += 1LL * szb * vc;
		for (int j : g[gb]) {
			ans[j] += pot[gb] + 1LL * sza * vc - pot[id[va]];
			g[ga].push_back(j);
		}
		pot[gb] = 0;
		for (int j : g[gb]) id[j] = ga;
		g[gb].clear();
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] + pot[id[0]] << endl;
	}
	return 0;
}

Measured memory_bytes: 14072
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,s0;
	int q;cin>>s>>q;
	while(q--){
		int a,b;cin>>s0;
		if(s0=="replace"){
			cin>>a>>b>>s0;
			for(int i=a;i<=b;i++)s[i]=s0[i-a];
		}else if(s0=="reverse"){
			cin>>a>>b;s0="";
			for(int i=a;i<=b;i++)s0+=s[i];
			for(int i=a;i<=b;i++)s[i]=s0[b-i];
		}else{
			cin>>a>>b;
			for(int i=a;i<=b;i++)cout<<s[i];cout<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

typedef pair<int, int> P;

int main()
{
	int w,h;
	while (cin >> w >> h, w || h) {
		vector< vector< P > > road(w, vector < P >(h,P(0,0)));
		for (int i = 1; i < w; i++) {
			road[i][0] = P(1,0);
		}
		for (int i = 1; i < h; i++) {
			road[0][i] = P(0, 1);
		}
		for(int i = 1;i < w;i++){
			for (int j = 1; j < h; j++) {
				road[i][j].first += road[i - 1][j].first;
				if (i >= 2) {
					road[i][j].first += road[i - 2][j].second;
				}
				road[i][j].second += road[i][j - 1].second;
				if (j >= 2) {
					road[i][j].second += road[i][j - 2].first;
				}
				if (road[i][j].first >= 100000)
					road[i][j].first %= 100000;
				if (road[i][j].second >= 100000)
					road[i][j].second %= 100000;
			}
		}
		int res = road[w - 1][h - 1].first + road[w - 1][h - 1].second;
		if (w >= 2)
			res += road[w - 2][h - 1].second;
		if (w >= 2)
			res += road[w - 1][h - 2].first;
		res %= 100000;
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
cnt = [0]*100005
s = sum(A)
for i in A:
    cnt[i] += 1
for i in range(Q):
    B, C = map(int,input().split())
    s += (C-B)*cnt[B]
    print(s)
    cnt[C] += cnt[B]
    cnt[B] = 0

Measured memory_bytes: 20320
from itertools import product

N,M,X=map(int,input().split())
C=[0]*N
A=[[0] for _ in range(N)]
for i in range(N):
  C[i],*A[i] = map(int,input().split())
  
s= product([1,0],repeat=N)
ans=float("inf")

for kumi in s:
  gou=True
  cost=0
  R=[0 for _ in range(M)]
  for i,n in enumerate(kumi):
    for j in range(M):  #アルゴリズム
      R[j] +=n*A[i][j]
    cost +=n*C[i]
  #print(R,cost)
  for pt in R:
    if pt<X:
      gou=False
  if gou:
    ans=min(ans,cost)
else:
  if ans!=float("inf"):
    print(ans)
  else:
    print(-1)

Measured memory_bytes: 9040
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int x;
  cin>>x;
  int ans = 10 - x / 200;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll a,b,c=0;

int main() {
    ll A,B;
    cin >> A >> B;
    if(A%4==0){
        a=0;
    }
    if(A%4==1){
        a=A-1;
    }
    if(A%4==2){
        a=1;
    }
    if(A%4==3){
        a=A;
    }
    if(B%4==0){
        b=B;
    }
    if(B%4==1){
        b=1;
    }
    if(B%4==2){
        b=B+1;
    }
    if(B%4==3){
        b=0;
    }
    c=a^b;
    cout << c << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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; }

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示


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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	double n,m,s;
	while(cin>>n>>m>>s,n){
		int ans=0;
		n+=100;
		m+=100;
		for(int i=1;i<1000;i++){
			for(int j=1;j<1000;j++){
				int p1=i*n/100;
				int p2=j*n/100;
				if(p1+p2==s){
					int p1=i*m/100;
					int p2=j*m/100;
					ans=max(ans,p1+p2);
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1216
#2020-05-28 22:26:38
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N, M = map(int,input().split())

def modify(x,y):
    if x>y:
        x,y = y,x
    return (x,y)


edge = [[] for _ in range(N)]
edgeid = dict()
for k in range(M):
    u,v,r = map(int,input().split())
    edge[u-1].append((v-1, r))
    edge[v-1].append((u-1, r))
    edgeid[modify(u-1,v-1)] = k

from heapq import heappop,heappush, heapify
INF = 10**20
def dijkstra2(S, N, Edge):
    # S: start vertex
    # N: number of vertices
    # Edge: adjacent list [node, cost]
    

    dist = [INF]*N
    dist[S] = 0
    root = [-1]*N
    que = [(0, S)]
    heapify(que)
    
    while que:
        c, v = heappop(que)
        if dist[v] < c: continue

        for nv, nc in Edge[v]:
            if c+nc < dist[nv]:
                dist[nv] = c+nc
                root[nv] = v
                heappush(que, (c+nc, nv))
    
    return [dist, root]

def find_path(S,T,root):
    # SからTへのパスを逆順で返す
    path = []
    cur = T
    while cur!=S:
        past = root[cur]
        path.append((past, cur))
        cur = past
    return path

unused_flag = [True] * M
for start in range(N):
    dist, root = dijkstra2(start, N, edge)
    for goal in range(N):
        if start==goal:continue
        for p in find_path(start, goal, root):
            unused_flag[edgeid[modify(p[0],p[1])]] = False

print(sum(unused_flag))

Measured memory_bytes: 56796
#include <bits/stdc++.h>
using namespace std;
long long n,h[200002],ok[200002];
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
     cin>>n;
     for(int i=1;i<n+1;i++)
         cin>>h[i];
         ok[1]=0;
         ok[2]=abs(h[2]-h[1]);
     for(int i=3;i<n+1;i++){
     	
	 ok[i]=min(ok[i-1] + abs(h[i] - h[i-1]), ok[i-2] + abs(h[i] - h[i-2]));
	 }
	 cout<<ok[n];
return 0;
}

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

int main() {
    int k,n,ans=0;
    cin >>k>>n;
    int a[n];
    rep(i,n)cin >>a[i];
    sort(a,a+n);
    rep(i,n-1){
        if(ans<a[i+1]-a[i])ans=a[i+1]-a[i];
    }
    if(ans<a[0]-a[n-1]+k)ans=a[0]-a[n-1]+k;
    cout << k-ans <<endl;
    return 0;
}

Measured memory_bytes: 1024
N, A, B = map(int, input().split())
numbers = [x for x in range(1, N + 1)]
ans = 0
for number in numbers:
  digit_sum= sum([int(x) for x in list(str(number))])
  if digit_sum<= B and digit_sum>= A:
    ans += number
    
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = Integer.parseInt(scan.next());

        int b = a % 10;
        int c = a / 10 % 10;
        int d = a / 100 % 10;

        System.out.println(b + c + d);
    }
}

Measured memory_bytes: 23124
import numpy as np

def main():
    a,b,c = input().split(' ')
    a = int(a)
    b = int(b)
    c = int(c)

    onemax = a
    one = b
    two = c

    yoryoku = onemax - one

    if c > yoryoku:
        print(c - yoryoku)
    else:
        print(0)



if __name__ == "__main__":
    main()

Measured memory_bytes: 18460
#include<stdio.h>

int m, d, i, a;
char d1, d10;

int main(void){
	scanf("%d%d", &m, &d);
	for(i=1; i<=d; i++){
		d1 = i/10;
		d10 = i%10;
		if(d1>=2 && d10>=2 && d1*d10<=m){
			a++;
		}
	}
	printf("%d\n", a);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int sum=0;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        sum+=__gcd(i,__gcd(j,k));
      }
    }
  }
  cout<<sum<<"\n";
  return 0;
}


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


int main(){

  int n;
  cin >> n;
  int a[n];
  int maxa=0;
  int mina=INT_MAX;
  for(int i=0; i<n; i++){
    cin >> a[i];
    maxa = max(maxa,a[i]);
    mina = min(mina,a[i]);
  }
  cout << (maxa - mina) << endl;
  
  return 0;
}


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

int d[2][100000];
vector <int> v[100000];

void dfs(int x, int y, int z, int w) {
    int i;
    d[w][x] = z;
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;

        dfs(v[x][i], x, z + 1, w);
    }
}

int main() {
    int n;

    scanf("%d", &n);

    for (int i=0;i<n-1;i++){
        int x, y;
        scanf("%d %d", &x, &y);
        x--;
        y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    dfs(0, -1, 0, 0);
    dfs(n - 1, -1, 0, 1);

    int c1=0,c2=0;
    for (int i=0;i<n;i++){
        if (d[0][i] <= d[1][i]) {
            c1++;
        } else {
            c2++;
        }
    }

    if (c1 > c2) {
        printf("Fennec\n");
    } else {
        printf("Snuke\n");
    }
    return 0;
}


Measured memory_bytes: 14336
import java.util.Scanner;

public class Main {
    public static void main(String[] a){
        Scanner scanner=new Scanner(System.in);
        //int t=scanner.nextInt();
//        String string=scanner.next();
//        int aa=0,b=0;
//        for(int j=0;j<string.length();j++){
//            if(string.charAt(j)=='A'){
//                aa++;
//            }
//            else{
//                b++;
//            }
//        }
//        if(aa==0 || b==0){
//            System.out.println("No");
//        }
//        else{
//            System.out.println("Yes");
//        }
       // int n=scanner.nextInt();
        double aa=scanner.nextDouble();
        double b=scanner.nextDouble();
        int ans=-1;
        for(int j=1;j<=1333;j++){
            double ss=(double)Math.floor(0.08*(double)j);
            double ff=(double)((double)Math.floor(0.10*(double)(double)j));
            if(ss==aa && ff==b){
                ans=(int)j;
                break;
            }
        }
        System.out.println(ans);
//        if(ss>ff){
//            System.out.println(ff);
//        }
//        else{
//            System.out.println(-1);
//        }
    }
}


Measured memory_bytes: 24756
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
int N;
int a[10],b[10],c[10],d[10];


int main()
{
	ios;
	int cnt=1,res,ans,flag=0,ca=0;
	cin>>N;
	for(int i=0;i<N;i++) 
	{
		cin>>a[i];
		c[i]=a[i];
	}
	for(int i=0;i<N;i++) cin>>b[i];
	sort(c,c+N);
	do{
		flag=0;
		for(int i=0;i<N;i++)
		{
			if(c[i]!=a[i])
			{
				flag=1;
				break;	
			}
		}
		if(!flag) 
		{
			ans=cnt;
			break;
		}
		cnt++;
	}while(next_permutation(c,c+N));
	
	sort(c,c+N);
	cnt=1;
	
	do{
		ca=0;
		for(int i=0;i<N;i++)
		{
			if(c[i]!=b[i])
			{
				ca=1;
				break;	
			}
		}
		if(!ca) 
		{
			res=cnt;
			break;
		}
		cnt++;
	}while(next_permutation(c,c+N));
	cout<<abs(ans-res)<<"\n";
	return 0;
}

Measured memory_bytes: 3644
import copy
N = int(input())
Ai = list(map(int, input().strip().split()))
height = 0;
boards = copy.copy(Ai)
for i in range(len(boards)-1):
    if boards[i+1] >= boards[i]:
        continue;
    else:
        height += boards[i] - boards[i + 1]
        boards[i+1]= boards[i]
print(height)

Measured memory_bytes: 33316
s = input()
s = s.replace("BC", "X")

ans = 0
a_count = 0

for i in range(len(s)):
    if s[i] == "A":
        a_count += 1
    elif s[i] == "X":
        ans += a_count
    else:
        a_count = 0

print(ans)

Measured memory_bytes: 3500
/*****include*****/
#include <iostream>
#include <fstream>
#include <string>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	int n;
	double x[4];
	double y[4];
	double slope_AB;
	double slope_CD;
	/*****処理部*****/
	cin >> n;
	for(int loop=0;loop<n;loop++){
		for(int i=0;i<4;i++){
			cin >> x[i];
			cin >> y[i];
		}
		slope_AB = (y[0] - y[1])/(x[0] - x[1]);
		slope_CD = (y[2] - y[3])/(x[2] - x[3]);
		if(slope_AB == slope_CD)	cout << "YES" << endl;
		else						cout << "NO" << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN=55;
int n,c,L[MAXN],per[MAXN],dp[MAXN<<3][1<<5|1];
long double ans;
inline int calc()
{
	for(register int i=0;i<=n*c;i++)
		for(register int sel=0;sel<(1<<(n-1));sel++) dp[i][sel]=0;
	dp[n*L[n]][0]=1;
	for(register int i=0;i<=n*c;i++)
		if(i%n)
		{
			register int x=per[i%n];
			for(register int sel=0;sel<(1<<(n-1));sel++)
				if(!(sel&(1<<(x-1))))
					for(register int j=i;j<=n*c;j++) dp[min(max(j,i+n*L[x]),n*c)][sel|(1<<(x-1))]+=dp[j][sel];
		}
	return dp[n*c][(1<<(n-1))-1];
}
signed main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>c;
	for(register int i=1;i<=n;i++) cin>>L[i];
	sort(L+1,L+n+1);
	for(register int i=1;i<n;i++) per[i]=i;
	do {ans+=calc();}
	while(next_permutation(per+1,per+n));
	for(register int i=1;i<n;i++) ans=ans*1.0/i/c;
	cout<<setprecision(20)<<ans<<endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    string s[102];
    int t[102];
    for(int i = 0; i < n; i++) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    int i = 0;
    for(; i < n; i++) if(s[i] == x) break;
    i++;
    int ans = 0;
    for(; i < n; i++) ans += t[i];
    cout << ans << endl;
}

Measured memory_bytes: 764
///BISMILLAH'IR  RO'HMANIR  ROH'IM
///RIFAT SHARIAR SAKIL
///SOFTWARE ENGINEERING(SUST)

#include<stdio.h>
int main()
{
    int N,s;
    scanf("%d",&N);
    s=N*N*N;
    printf("%d",s);
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;

    int d = abs(A-B);
    bool ok = (d <= T * (V-W));

    cout << (ok ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
//int dx[]={+1,-1,+0,+0};///Four Directions
//int dy[]={+0,+0,+1,-1};///Four directions
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions

//int mark[10007];vi prime;void seive(){for(int i=2;i<10000;i++){if(mark[i]==0){prime.pb(i);for(int j=i+i;j<=10000;j+=i)mark[j]=1;}}}

//freopen("input.txt", "r", stdin);

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

   string s; cin>>s;
   bool f=0;
   for(int i=0;i<3;i++) if(s[i]=='7') f=1;

   if(f) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
    End;
}


Measured memory_bytes: 3652
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <string>
using std::string;

int main(void){
    const char table[] = "0123456789";
    string str;

    int N, K;
    cin >> N >> K;

    while(N >= K){
        str += table[N%K];
        N = (int)N/K;
    }
    str += table[N];

    cout << str.length() << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(void){
    int x; cin >> x;
    ll cnt=0;
    for(int i=1;i<=x;i++){
        cnt+= i;
        if(x <= cnt){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<set<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

// int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;



int main() {

  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  REP(i, N)cin >> H[i];
  Graph G(N);
  REP(i, M){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].insert(H[b]);
    G[b].insert(H[a]);
  }
  ll count = 0;

  REP(i, N){
    if(G[i].size() == 0){
      count++;
    }else {
      if(H[i] > *(G[i].rbegin())){
        count++;
      }
    }
  }

  cout << count << endl;



}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 18040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 1000006;
const ll MOD = 1000000007;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

ll n, k, a[MAXN];
tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> st;
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n >> k;

    ll sum = 0;
    st.insert(0);

    ll ans = 0;
    REP (i, n) {
        cin >> a[i];
        a[i] -= k;
        sum += a[i];
        ans += st.order_of_key(sum + 1);
        debug(sum, ans);
        st.insert(sum);
    }

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


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define pa pair<int,int>
#define st first
#define nd second
#define ld long double
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const ll inf=1e18+9;
//A B C D H F E I G K L M N P S O Q R J U Z Y X T V W
const int MAX=500;
ll dp[MAX][MAX];
const int mod=1e9+7;

int main()
{
    int n;
    scanf("%d",&n);
    ll tab[n+1];
    ll pref[n+1];
    pref[0]=0;
    ll kas=0;
    for (int i=1; i<=n; i++)
    {
        scanf("%lld",&tab[i]);
        kas+=tab[i];
        pref[i]=kas;
    }
    for (int l=n; l>=1; l--)
    {
        for (int r=l; r<=n; r++)
        {
            if (l==r)
            {
                dp[l][r]=0;
            }
            else
            {

                ll minimum=inf;
                ll suma=pref[r]-pref[l-1];
                for (int k=l; k<=r-1; k++)
                {
                    minimum=min(minimum,dp[l][k]+dp[k+1][r]+suma);
                }
                dp[l][r]=minimum;
            }
        }
    }
    /*
    for (int i=1; i<=n; i++)
    {
        for (int j=i; j<=n; j++)
        {
            cout<<dp[i][j]<<" "<<i<<" "<<j<<"\n";
        }
    }
    */

    printf("%lld",dp[1][n]);

    return 0;
}




Measured memory_bytes: 1920
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
ans = inf
for i in range(min(a), max(a) + 1):
    tmp = 0
    for j in range(n):
        tmp += (a[j] - i) ** 2
    ans = min(ans, tmp)
print(ans)

Measured memory_bytes: 5396
k = int(input())
rem = 7%k
alreadys = [False]*k
alreadys[rem] = True

ans = 1
while True:
    if rem == 0:
        print(ans)
        exit()
    ans += 1
    rem = (rem*10+7)%k
    if alreadys[rem]:
        print(-1)
        exit()
    alreadys[rem] = True

Measured memory_bytes: 71116
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

int N;

int main() {

    cin >> N;
    vector<int> p(N+1, 0);
    for (int i = 1; i < N+1; i++) {
        scanf("%d", &p[i]);
    }

    int ans = 0;
    int cnt = 0;
    for (int i = 1; i < N+1; i++) {
        if (i == p[i]) cnt++;
        else {
            ans += (cnt + 1) / 2;
            cnt = 0;
        }
    }
            ans += (cnt + 1) / 2;

    cout << ans << '\n';

}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    int n;
    int d[101][101];
    int i,j;
    scanf("%d",&n);
    int count=0;
    
    for(i=0;i<n;i++){
        for(j=0;j<2;j++){
            scanf("%d",&d[i][j]);
        }
    }
    
    
    for(i=0;i<n;i++){
            if(d[i][0]==d[i][1]) count++;
            if(d[i][0]!=d[i][1]) count=0;
            
            if(count==3) break;       
                        
            
            
            
            
            
            
    }  
    if(count==3) printf("Yes");
    else printf("No");
    
    return 0;
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
using namespace std;
long long int mod =1000000007;
long long int modularExponentiation(long long int x,long long int n,long long int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modularExponentiation((x*x)%M,n/2,M);
    else                             
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;

}
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k; cin>>n>>k;
    vector<long long int>g;
    for(long long int i=1;i<=k;i++)
    {
        
        long long int a = modularExponentiation(k/i,n,mod);
        g.push_back(a);
    }
    long long int sum =0; long long int j;
    for(long long int i=k;i>=1;i--)
    {
        for( j=i*2;j<=k;j=j+i)
        {
            g[i-1]=(g[i-1]%mod - g[j-1]%mod +mod)%mod;
        }
        sum = (sum%mod + (((i%mod)*(g[i-1]%mod))%mod)%mod)%mod;
        
        
    }
    cout<<sum<<"\n";
}

Measured memory_bytes: 4288
//////AGC039-B//////
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll n,ans=0;
void Main(){
    cin>>n;
    vector<ll> l(n);
    For(i,0,n)cin>>l.at(i);
    sort(ALL(l));
    For(i,0,n-2){
        For(j,i+1,n-1){
            auto iter=lower_bound(ALL(l),l.at(i)+l.at(j));
            ans+=iter-l.begin()-(j+1);
        }
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}


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

using ll=long long;
const ll INF=1e10;
int main(){
    int n;
    cin>>n;
    vector<vector<ll>> a(n,vector<ll>(n));
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) cin>>a[i][j];
    ll res=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            bool need=true;
            for(int k=0;k<n;k++){
                if(k==i || k==j) continue;
                if(a[i][j]>a[i][k]+a[k][j]){
                    cout<<-1<<endl;
                    return 0;
                }
                else if(a[i][j]==a[i][k]+a[k][j]){
                    need=false;
                }
            }
            if(need) res+=a[i][j];
        }
    }
    cout<<res<<endl;
    
    return 0;
}

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

const int N = 200005;

int n, h, w;
int a[N], r[N], c[N];

int rt[N], sz[N], t[N];

int find_rt(int x) {
    if (rt[x] == x) return x;
    return rt[x] = find_rt(rt[x]);
}

struct cell {
    int r, c, v;
    cell(int r = 0, int c = 0, int v = 0) : r(r), c(c), v(v) {}
    bool operator < (const cell a) const {return v > a.v;}
} ;

long long ans;

vector <cell> A;

bool comb(int r, int c) {
    int x = find_rt(r), y = find_rt(h+c);
    if (x == y) {
        if (sz[x] - t[x] > 0) {
            t[x] ++;
            return 1;
        }
        else return 0;
    }
    else {
        if (sz[x] + sz[y] > t[x] + t[y]) {
            rt[x] = y;
            t[y] += t[x];
            sz[y] += sz[x];
            t[y] ++;
            return 1;
        }
        else return 0;
    }
}

int main() {
    scanf("%d %d %d", &n, &h, &w);
    for (int i = 1; i <= h+w; i ++) rt[i] = i, sz[i] = 1, t[i] = 0;
    for (int i = 1; i <= n; i ++) {
        int r, c, v;
        scanf("%d %d %d", &r, &c, &v);
        A.push_back(cell(r, c, v));
    }
    sort(A.begin(), A.end());
    for (auto x : A) {
        int r = x.r, c = x.c;
        if (comb(r, c)) ans += x.v;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6008
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();
    System.out.println(d / s < t || (d / s == t && d % s == 0) ? "Yes" : "No");
  }
}


Measured memory_bytes: 27076
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   char a, b;
   cin >> a >> b;
   if (a == b) cout << 'H' << endl;
   else cout << 'D' << endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int i;
  int a,b,flag=0;
  cin>>a>>b;
  for(i=max(b*10,(int)(a*12.5));i<min((b+1)*10,(int)((a+1)*12.5));i++){
    if((int)(i*0.1)==b&&(int)(i*0.08)==a){
      flag++;
      break;
    }
      
  }
  if(flag==1){
    cout<<i<<endl;
  }
  else{
    cout<<-1<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin>>n;
  map<ll,ll>cnt;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    cnt[a]++;
  }
  ll ans=0;
  for(auto a:cnt){
    ans+=max(a.S%a.F,a.S-a.F);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6272
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

r = int(input())
print(r*r)

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

using namespace std;

typedef long long ll;
#define rep(i,m,n) for(ll i=m;i<n;i++)

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

  ll a,b,x;
  cin  >> a >> b >> x;
  
  if(a*a*b<=2*x) cout << setprecision(9) << atan(2.0*(a*a*b-x)/(a*a*a))*180.0/3.14159265358979 << endl;
  else cout << setprecision(9) << atan((a*b*b)/(2.0*x))*180.0/3.14159265358979 << endl;
 
  
}

Measured memory_bytes: 256
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    N = [int(c) for c in input().strip()]

    op = list(product([1, -1], repeat=3))
    for o in op:
        if N[0] + N[1] * o[0] + N[2] * o[1] + N[3] * o[2] == 7:
            ans = str(N[0])
            for i in range(3):
                if o[i] == 1:
                    ans += '+' + str(N[i+1])
                else:
                    ans += '-' + str(N[i+1])
            ans += '=7'
            break

    print(ans)
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args)throws Exception {
        InputReader in = new InputReader (System.in);
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        // Code starts from here //
        long start = in.nextLong();
        long end = in.nextLong();
        long x = in.nextLong();
        long ans = countDivisors(start, end, x);
        if(start % x == 0) pw.println((ans + 1));
        else pw.println(ans);
        pw.close();
    }

    static long countDivisors(long start, long end, long x) {
        return (end / x) - (start / x);
    }






    /****************************************
     ******* IO STUFF STARTS FROM HERE ******
     ****************************************/

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString
                (obj));
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new
                    InputStreamReader(stream));
            tokenizer = null;
        }

        //InputReader in = new InputReader(new FileReader("File_Name"));
        public InputReader(FileReader file) {
            reader = new BufferedReader(file);
            tokenizer = null;
        }

        public String next() {

            try {
                while (tokenizer == null || !
                        tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer
                            (reader.readLine());
            } catch (IOException e) {
                return null;
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            String line = null;
            try {
                tokenizer = null;
                line =  reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }

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

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

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

        public boolean hasNext(){
            try {
                while (tokenizer == null || !
                        tokenizer.hasMoreTokens())
                    tokenizer = new StringTokenizer
                            (reader.readLine());
            }
            catch (Exception e) {
                return false;
            }
            return true;
        }
    }
}

Measured memory_bytes: 32944