akhauriyash/Code-Regression huggingface dataset:
N=int(input().strip())
A = list(map(int, input().strip().split()))
B = list(map(int, input().strip().split()))
C = list(map(int, input().strip().split()))

satisf = 0
for i in range(N):
    satisf += B[A[i]-1]
    if i<N-1:
        if A[i+1]-A[i]==1:
            satisf+=C[A[i]-1]
print(satisf)

Measured memory_bytes: 3064
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int n;
  cin >> n;
  int M=0,m=0xFFFF;
  rep(i,0,n){
    int a;
    cin >> a;
    M = max(a,M);
    m = min(a,m);
  }
  P(M-m);
  ret 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) for (int i = 0; i < b; i++) cout << a;
    else for (int i = 0; i < a; i++) cout << b;
    cout << endl;

    return (0);
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i)-1 for i in input().split()]

    edge = [set() for _ in range(N)]

    for i, a in enumerate(A):
        edge[i].add(a)

    ans = 0
    for i, a in enumerate(A):
        if i in edge[a]:
            ans += 1
    print(ans//2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74604
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define ll long long
vector<ll> a[4];
map<ll, ll> b;
int main(){
	ll x, y, n, m, num, sum = 0;
	scanf("%lld%lld", &n, &m);
	for(int i = 0; i < n; ++i){
		scanf("%lld%lld", &x, &y);
		if(i == 0) num = x, a[x-num].push_back(y);
		else a[x-num].push_back(y);
		sum += x;
	}
	m = min(sum, m);
	b[0] = 0;
	ll num2 = (num > 1000 ? num : 1);
	for(int i = 0; i <= 3; ++i){
		for(int j = 0; j < a[i].size(); ++j){
			//cout<<a[i][j]<<"**"<<endl;
			for(ll k = m; k >= i+num; k -= num2){
				b[k] = max(b[k], b[k-num-i]+a[i][j]);
			}
		}
	}
	cout<<b[m]<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e16
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
signed main()
{
	string str; getline(cin, str);
	stringstream ss(str);
	stack<int>s;
	while (true)
	{
		ss >> str;
		if (!ss)break;
		try
		{
			s.push(stoi(str));
		}
		catch (std::invalid_argument)
		{
			int arg1 = s.top(); s.pop();
			int arg2 = s.top(); s.pop();
			switch (str.front())
			{
			case '+':
				s.push(arg2 + arg1);
				break;
			case '-':
				s.push(arg2 - arg1);
				break;
			case '*':
				s.push(arg2 * arg1);
				break;
			}
		}
	}
	cout << s.top() << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};

    int h,w; cin>>h>>w;
    vector<vector<char> > field(h, vector<char>(w));
    rep(i,h)rep(j,w){
        cin>>field[i][j];
    }
    int ans=-1;
    rep(i,h)rep(j,w){
        if (field[i][j]=='.'){
            queue<pi> Q;
            Q.emplace(i,j);
            int mdist = -1;
            vector<vi> dist(h, vi(w,-1));
            dist[i][j] = 0;
            while(Q.size()){
                pi p = Q.front(); Q.pop();
                int y = p.fi, x = p.se;
                rep(l,4){
                    int ty = y+dy[l];
                    int tx = x+dx[l];
                    if (!(0<=tx&&tx<=w-1&&0<=ty&&ty<=h-1)) continue;
                    if (field[ty][tx]=='#') continue; 
                    if (dist[ty][tx]==-1){
                        dist[ty][tx] = dist[y][x]+1;
                        mdist = max(mdist, dist[ty][tx]);
                        Q.emplace(ty,tx);
                    }
                }
            }
            ans = max(ans, mdist);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys,math,copy,queue,itertools,bisect,collections,heapq
sys.setrecursionlimit(10**7)
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
INF = 10**18
MOD = 10**9 + 7
DD = ((1,0),(-1,0),(0,1),(0,-1))

K = NI()
A,B = LI()
for i in range(A,B+1):
    if i % K == 0:
        print ('OK')
        break
else:
    print ('NG')

Measured memory_bytes: 68700
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll a,b,c,d,e,f;
  cin >>a>>b>>c>>d>>e>>f;
  double ans=0;
  ll aa=100*a,bb=100*b,w=(f/aa)*aa,s=0;
  for(ll i=0;i<=(f/aa);i++){
   for(ll j=0;j<=((f-aa*i)/bb);j++){
     if(i==j&&i==0) break;
     ll k=i*100*a+j*100*b;
     if(k<=f){
       ll u=f-k;
        for(ll p=0;p<=(u/c);p++){
          for(ll q=0;q<=((u-p*c)/d);q++){
            ll su=p*c+q*d;
            if((k/100)*e>=su){
              double t=(double)(100*su)/(k+su);
              if(ans<t){
                ans=t;
                w=k;
                s=su;
              }
            }
          }
        }
     }
   }
 }
  cout<<w+s<<" "<<s<<endl;
  }


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


int main (){
    int H, W;
    cin>>H>>W;
    vector<vector<char>> Vec(H, vector<char>(W));
    vector<vector<int>> Ue(H, vector<int>(W));
    vector<vector<int>> Shita(H, vector<int>(W));
    vector<vector<int>> Migi(H, vector<int>(W));
    vector<vector<int>> Hidari(H, vector<int>(W));
    
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin>>Vec.at(i).at(j);
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(Vec.at(i).at(j)=='#'){
                Hidari.at(i).at(j)=-1;
            }
            else if(j==0){
                Hidari.at(i).at(j)=0;
            }
            else{
                Hidari.at(i).at(j)=Hidari.at(i).at(j-1)+1;
            }
        }
    }
    for(int i=0; i<H; i++){
        for(int j=W-1; j>=0; j--){
            if(Vec.at(i).at(j)=='#'){
                Migi.at(i).at(j)=-1;
            }
            else if(j==W-1){
                Migi.at(i).at(j)=0;
            }
            else{
                Migi.at(i).at(j)=Migi.at(i).at(j+1)+1;
            }
        }
    }
    for(int j=0; j<W; j++){
        for(int i=0; i<H; i++){
           if(Vec.at(i).at(j)=='#'){
                Ue.at(i).at(j)=-1;
            }
            else if(i==0){
                Ue.at(i).at(j)=0;
            }
            else{
                Ue.at(i).at(j)=Ue.at(i-1).at(j)+1;
            } 
        }
    }
    
    for(int j=0; j<W; j++){
        for(int i=H-1; i>=0; i--){
            if(Vec.at(i).at(j)=='#'){
                Shita.at(i).at(j)=-1;
            }
            else if(i==H-1){
                Shita.at(i).at(j)=0;
            }
            else{
                Shita.at(i).at(j)=Shita.at(i+1).at(j)+1;
            } 
        }
    }
    int MaxS=0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
          	if(Vec.at(i).at(j)=='#'){
            	continue;
            }
            MaxS=max(MaxS, Migi.at(i).at(j)+ Hidari.at(i).at(j)+ Ue.at(i).at(j)+ Shita.at(i).at(j) +1);
        }
    }
    cout<<MaxS;
    

}

Measured memory_bytes: 67072
N = int(input())
W = list(map(int, input().split()))

_sum = sum(W)

_sum_f = W[0]
_sum_b = _sum-_sum_f
min_sa=abs(_sum_f-_sum_b)
for i in range(1,N,1):
    _sum_f+=W[i]
    _sum_b = _sum-_sum_f
    sa=abs(_sum_f-_sum_b)
    if sa<min_sa:
        min_sa=sa
    else:
      break
print(min_sa)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N;
    cin >> N;
    string ans;
    N--;
    for(;;){
        if(ans.size()==0){
            ans.push_back('a'+N%26);
        }
        else{
            ans.push_back('a'+(N-1)%26);
            N--;
        }
        if(N<26) break;
        else{
            N/=26;
        }
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define push push
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<<endl;}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define minpq(x) x,vector<x>,greater<x>
#define ln length()
#define sz size()
#define inf 1e18;
const int mod= 1e9+7;

void solve(){
   int n,a[1000];
   cin>>n;
   rep(i,0,n){
       cin>>a[i];
   }
   sort(a,a+n);
   multiset <pair<int,pair<int,int>> > ans;
   rep(i,0,n){
       rep(j,i+1,n){
           rep(k,j+1,n){
               if(a[i]+a[j]>a[k]){
//                   cout<<a[i]<<" "<<a[j]<<" "<<a[k]<<endl;
                    if(a[i]!=a[j] && a[j]!=a[k])
                   ans.insert({a[i],{a[j],a[k]}});
               }
           }
       }
   }
   cout<<ans.sz<<endl;
}

int32_t main(){
    fastIO
//    #ifndef ONLINE_JUDGE
//        freopen("C:\\Users\\swast\\CLionProjects\\untitled\\input.txt", "r", stdin);
//    #endif
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 13640
#include <bits/stdc++.h>
using namespace std;
#define ALL(c) (c).begin(),(c).end()
#define int long long

void solve(long long N, vector<long long> A){
	sort(ALL(A));

	if (N % 2 == 0) {
		int a = 0, b = 0;
		for(int i = 0; i < N / 2; ++i) {
			a += A[i];
		}
		for(int i = N / 2; i < N; ++i) {
			b += A[i];
		}
		cout << 2 * (b - a) + A[N / 2 - 1] - A[N / 2] << endl;
	} else {
		int a = 0, b = 0;
		for(int i = 0; i < N / 2; ++i) {
			a += A[i];
		}
		for(int i = N / 2; i < N; ++i) {
			b += A[i];
		}
		int res = 2 * (b - a) - A[N / 2] - A[N / 2 + 1];
		a = b = 0;
		for(int i = 0; i <= N / 2; ++i) {
			a += A[i];
		}
		for(int i = N / 2 + 1; i < N; ++i) {
			b += A[i];
		}
		res = max(res, 2 * (b - a) + A[N / 2] + A[N / 2 - 1]);
		cout << res << endl;
	}
}

signed main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}


Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    N%=K;
    prt(min(N,K-N));

    return 0;
}



Measured memory_bytes: 3608
import numpy as np
X, N = list(map(int,input().split()))
if N == 0:
  print(X)
else:
  P = list(map(int,input().split()))
  if P.count(X) == 0:
    print(X)
  else:
    L = list(np.arange(-1,102))
    for i in range(len(P)):
      L.remove(P[i])
    A = []
    for j in range(len(L)):
      A.append([abs(X-L[j]),L[j]])
    ans = 0
    for k in range(len(A)):
      if A[k][0]== min(A)[0]:
        ans = A[k][1]
        break
    print(ans)

Measured memory_bytes: 27140
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int N;
  long long K;
  cin >> N >> K;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
    A[i]--;
  }
  
  
  int loop = 0;
  int start = 0; 
  bool Seen[N];
  for(int i=0;i<N;i++) Seen[i]=false;
  Seen[0]=true;
  vector<int> B;
  B.push_back(0);
  int arriveat=0;
  
  for(int i=0;i<N;i++){
    loop++;
    arriveat = A[arriveat];
    if(!Seen[arriveat]){
      Seen[arriveat] = true;
      B.push_back(arriveat);
    }
    else{
      start = arriveat;
      break;
    }
  }
  
  int lpfirst;
  int lpnum;
  for(int i=0;i<loop;i++){
    if(B.at(i)==start){
      lpnum = loop - i;
      lpfirst = i;
      break;
    }
  }
  
  if(lpfirst > K){
    cout << B.at(K)+1 << endl;
  }else{
    int res;
    res = (K - lpfirst) % lpnum;
    cout << B.at(lpfirst + res)+1 << endl;
  }
  
}


Measured memory_bytes: 5160
import bisect
from collections import defaultdict
S = input()
T = input()
len_S = len(S)
s2i = defaultdict(list)
for i, si in enumerate(S):
    s2i[si].append(i)
ans = 1
pi = -1
for ti in T:
    si = s2i.get(ti)
    if not si:
        ans = -1
        break
    il = bisect.bisect_right(si,pi)
    if len(si) <= il:
        ans += len_S
        pi = si[0]
    else:
        pi = si[il]

if ans != -1:
    ans += pi

print(ans)


Measured memory_bytes: 45808
"use strict"

function Main(input) {
  input = input.trim().split('\n');
  let N = Number(input[0]);
  let A = input[1].trim().split(' ').map(Number);  

  let eao = {};
  for(let i=0; i<N; i++){
    let tmp = A[i];
    if(tmp%2===0){
      eao['even'] = eao['even'] ? eao['even'] + 1 : 1;
    }else{
      eao['odd'] = eao['odd'] ? eao['odd'] + 1 : 1;
    };
  };

  if(eao['odd']%2 !== 0){
    console.log('NO');
    return
  }
  console.log('YES');
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17484
N = int(input())
a = 0
for i in range(N):
  a = list(map(int, input().split()))
  if a[0] < sum(a) - a[0]:
    print("No")
    exit()
  if (sum(a) - a[0] - a[0])%2 != 0:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	//input
	int N; int K; cin >> N >> K ;
	string S; cin >> S;
	
	//compute
	string ans;
	for (int i = 0; i < N; i++){
		if (i == K-1){
			if (S[i] == char('A')){S[i] = char('a');}
			else if (S[i] == char('B')){S[i] = char('b');}
			else if (S[i] == char('C')){S[i] = char('c');}
		}
		ans = ans + S[i];
	}
	//output
	cout << ans << endl;
} 

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

using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,k,h) for(int i = k; i < h; ++i)
#define rep3(i,k,h) for(int i = k; i <= h; ++i)
#define INF LLong_MAX // long long INF
#define inf INT_MAX // int inf

typedef pair<int,int> int_pair;
typedef pair<string,string> string_pair;


int main() {
    int h,n,res=0;
    cin >> h >> n;
    rep(i,n) {
        int b;
        cin >> b;
        res += b;
    }
    if(res >= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

bool has3(int x) {
	while (x) {
		if (x % 10 == 3)return true;
		x /= 10;
	}
	return false;
}

void call(int n) {
	for (int x = 1; x <= n; x++) {
		if (x % 3 == 0 || has3(x))cout << ' ' << x;
	}
	cout << endl;
}

int main() {
	int n;
	cin >> n;
	call(n);

	return 0;
	}

Measured memory_bytes: 1160
S = input()
K = int(input())

def ctoi(c):
    return ord(c) - ord('a')
def toa(c):
    i = ctoi(c)
    return (26-i)%26

ans = ''
for c in S:
    if len(ans)+1 == len(S):
        ans += chr((ctoi(c) + K)%26 + ord('a'))
    else:
        to = toa(c)
        if to <= K:
            ans += 'a'
            K -= to
        else:
            ans += c
print(ans)

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

using namespace std;

int main(){
    int n,k,f=0,tmp,chk;
    bool b[10]={0};
    scanf("%d %d",&n,&k);
    vector<int> d(k);
    for(auto&e:d) scanf("%d",&e);
    for (int i=0;i<k;i++) b[d[i]]=1;
    for (int i=n;i<100000;i++) {
        f=0;
        tmp=i;
        while (tmp>0) {
            chk=tmp%10;
            tmp/=10;
            if (b[chk]==1) {
                f=1;
                break;
            }
        }
        if (f==0 && i>=n) {
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

vec c;
void dfs(vvec &G,int now){
    c[now]=0;
    for(int next:G[now]){
        if(c[next]==0) continue;
        dfs(G,next);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    c.resize(n,-1);
    vvec G(n);
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        x--;y--;
        G[x].pb(y);
        G[y].pb(x);
    }
    
    ll ans=0;
    rep(i,n){
        if(c[i]==-1){
            ans++;
            dfs(G,i);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9600
#include <iostream>

using namespace std;

const int MOD = 1000000007;

int modinv(int b) {
  int exp = MOD - 2;
  int ans = 1;
  while (exp > 0) {
    if (exp & 1) ans = (long long)ans * b % MOD;
    b = (long long)b * b % MOD;
    exp >>= 1;
  }
  return ans;
}

int main() {
  int S; cin >> S;
  
  long long ans = 0;
  for (int n = 1; n <= S / 3; n++) {
    int a = max(n - 1, S - 3 * n);
    int b = min(n - 1, S - 3 * n);

    int numerator = 1;
    for (int i = S - 2 * n - 1; i > a; i--) {
      numerator = (long long)numerator * i % MOD;
    }

    int denominator = 1;
    for (int i = b; i > 1; i--) {
      denominator = (long long)denominator * i % MOD;
    }

    ans += (long long)numerator * modinv(denominator) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3648
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}

template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

int main(void) {
    ll n,c,k;
    cin>>n>>c>>k;
    vector<ll>t(n);
    rep(i,n){
        cin>>t[i];
    }
    sort(ALL(t));
    ll ans=0;
    ll time=t[0],next=0;
    ll m=0;
    while(next<n){
        ++ans;
        m=0;
        while(next<n&&time+k>=t[next]&&m<c){
            // cout<<t[next]<<" ";
            ++next;
            ++m;
        }
        // cout<<endl;
        time=t[next];
    }
    cout<<ans;
}


Measured memory_bytes: 4020
#include<iostream>
using namespace std;
int main() {
  int N;
  int D[100010];
  int c[100010];
  long p;
  long long ans=1,MOD=998244353;
  cin >> N;
  int i,j;
  for(i=0;i<100010;i++)c[i] = 0;
  for(i=0;i<N;i++)cin >> D[i];
  for(i=0;i<N;i++)c[D[i]]++;
  if(c[0] != 1 || D[0] != 0)ans = 0;
  for(i=1;i<N;i++) {
    p = 1;
    for(j=0;j<c[i];j++) {
      p *= c[i-1];
      p = p % MOD;
    }
    ans *= p;
    ans = ans % MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf
import Debug.Trace

import Data.STRef
import qualified Data.Map.Strict as M

readInt = ( readLn :: IO Int )
readInts = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m ] <- readInts
	as <- map ( `mod` m ) . scanl (+) 0 <$> readInts
	print $ solve m as

solve m as = solve' M.empty m as
	where
		solve' _ _ [] = 0
		solve' counts m (a:as) = res + solve' counts' m as
			where
				res = M.findWithDefault 0 (a `mod` m ) counts
				counts' = M.insertWith (+) a 1 counts

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


void solve(long long A, long double B){
    long double C = (long double)A * B;
    long long D = (long long)C;
    cout << D << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long double B;
    scanf("%Lf",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int M1 = h1 * 60 + m1, M2 = h2 * 60 + m2;
    int dif = M2 - M1;
    if (dif < 0) dif += 24 * 60;
    cout << max(dif - k, 0) << '\n';
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
using namespace __gnu_pbds;
typedef tree<pair<ll,pair<ll,ll> >, null_type, less<pair<ll,pair<ll,ll> > >, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
#define me BOSS
#define bug() cout<<"AIkahne aise"<<endl
#define PI acos(-1)
/* Precode Start Here *\
     Sieve
void sieve()
{
    for(ll i=3; i<=2000; i+=2)
    {
        for(ll j=i*i; j<=4000000; j+=i)
            A[j]=1;
    }
    v.push_back(2);
    for(ll i=3; i<=4000000; i+=2)
        if(A[i]==0)
            v.push_back(i);
}

     Power Function Modulo P

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    long res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}


   factorial

ll fact(ll n)
{
    ll ans=1;
    for(ll i=1;i<=n;i++)
    {
        ans=(ans*i)%mod;
    }
    return ans;
}
     Calculating nCr using Fermats law Theorem

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}


ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (ll i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (ll i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}
     num of divisor and euler totient

ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
    for(int i=1;i<=n;i++)
        phi[i]=i;
    for(int i=2;i<=n;i++)
    {
        if(!mark[i])
        {
            for(int j=i;j<=n;j+=i)
            {
                mark[j]=1;
                phi[j]*=(1-1/(double)i);
            }
        }
    }
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
            divi[j]++;
    }
}
/* Precode Ends */
#define mod 1000000007
ll A[5000001],B[5000001];
vector<ll>v;
map<ll,ll>myMap;
set<ll>mySet;
vector<pair<ll,ll> >vp;
priority_queue<ll> pq;
priority_queue<ll, vector<ll>, std::greater<ll> > first;
ll po(ll a,ll n)
{
  ll ans=1;
  for(int i=1;i<=n;i++)
       ans*=a;
    return ans;
}

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

ll x;
cin>>x;
for(int i=0;i<=120;i++)
{
    for(int j=-64;j<i;j++)
    {
        if(po(i,5)-po(j,5)==x)
        {
            cout<<i<<" "<<j<<endl;
            return 0;
        }
    }
}

return 0;
}



Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
 cin >> n;
 vector<int> a(3);
 for(int i=0;i<n;i++){
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(),a.end());
  if(a[0]*a[0] + a[1]*a[1] == a[2]*a[2]) cout << "YES" << endl;
  else cout << "NO" << endl;
 }
 return 0;
}


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

using namespace std;

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

    vector<int> vt(n);
    for (int i = 0; i < n; ++i) {
        cin >> vt[i];
    }

    int ans = *max_element(vt.begin(), vt.end()) -
              *min_element(vt.begin(), vt.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll D, T, S;
  cin >> D >> T >> S;
  if (T * S < D) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_V = 100005;

void dfs(int u, int prev, int cnt, int *visited, int *prenum, int *lowest, int *parent, vector< vector<int> > &v){
  visited[u] = true;
  prenum[u] = lowest[u] = cnt;
  REP(i, v[u].size()){
    int next = v[u][i];
    if(!visited[next]){
      parent[next] = u;
      dfs(next, u, ++cnt, visited, prenum, lowest, parent, v);
      lowest[u] = min(lowest[u], lowest[next]);
    } else if(next != prev)
      lowest[u] = min(lowest[u], prenum[next]);
  }
}

vector<int> articulation_points(int V, int E, vector< vector<int> > &v){
  int visited[V], prenum[V], lowest[V], parent[V];
  memset(visited, 0, sizeof(visited));
  parent[0] = -1;
  dfs(0, -1, 1, visited, prenum, lowest, parent, v);
  //cout <<"prenum" <<endl;
  //REP(i, V) cout <<i <<" : "<<prenum[i] <<endl;
  //cout <<"lowest" <<endl;
  //REP(i, V) cout <<i <<" : "<<lowest[i] <<endl;
  //cout <<"parent" <<endl;
  //REP(i, V) cout <<i <<" : "<<parent[i] <<endl;
  vector<int> ret;
  int cnt = 0, used[V];
  memset(used, 0, sizeof(used));
  FOR(i, 1, V){
    if(parent[i] == 0) ++cnt;
    if(parent[i] > 0 && !used[parent[i]] && prenum[parent[i]] <= lowest[i]){
      used[parent[i]] = true;
      ret.push_back(parent[i]);
    }
  }
  if(cnt >= 2) ret.push_back(0);
  return ret;
}

int main() {
  int V, E; cin >>V >>E;
  vector< vector<int> > v(V);
  REP(i, E){
    int f, t; cin >>f >>t;
    v[f].push_back(t);
    v[t].push_back(f);
  }
  vector<int> ans = articulation_points(V, E, v);
  SORT(ans);
  REP(i, ans.size()) cout <<ans[i] <<endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
typedef long long ll;

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

int main() {
    ll a, b;
    cin >> a >> b;
    ll gcd_ = gcd(a, b);
    ll ans = (a*b) / gcd_;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define int long long
using namespace std;

typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> L(M), R(M);
    REP(i, M){
        cin >> L[i] >> R[i];
        L[i]--;
        R[i]--;
    }
    vector<int> p(Q), q(Q);
    REP(i, Q){
        cin >> p[i] >> q[i];
        p[i]--;
        q[i]--;
    }

    vector< vector<int> > n_train(N, vector<int>(N, 0)), ans(N, vector<int>(N, 0));
    REP(i, M){
        n_train[L[i]][R[i]]++;
    }
    REP(i, N){
        FOR(j, i + 1, N){
            n_train[i][j] += n_train[i][j - 1];
        }
    }

    REP(i, N){
        ans[i][i] = n_train[i][i];
    }

    REP(j, N){
        for(int i = j - 1; i >= 0; i--){
            ans[i][j] = ans[i + 1][j] + n_train[i][j];
        }
    }

    REP(i, Q){
        cout << ans[p[i]][q[i]] << endl;
    }

    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(),A.end()
const long long mod=1000000007;
int main(){
    int N,T,c[1000],t[1000];
    cin>>N>>T;
    for(int i=0;i<N;i++)
    cin>>c[i]>>t[i];
    int ans=1001;
    for(int i=0;i<N;i++)
    {
        if(t[i]<=T)
        ans=min(ans,c[i]);
    }
    if(ans>1000)
    cout<<"TLE"<<endl;
    else
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a[5],dis,flag=0;
  for (int i=0;i<5;i++) scanf("%d",&a[i]);
  scanf("%d",&dis);
  for (int i=0;i<4;i++){
    for (int j=i+1;j<5;j++){
      if (a[j]-a[i]<=dis) flag++;
    }
  }
  if (flag==10) printf("Yay!\n");
  else printf(":(\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int D, N, T[200], A[200], B[200], C[200];
int dp[300][300];

int main() {
  cin >> D >> N;
  for(int i = 0; i < D; i++) cin >> T[i];
  for(int i = 0; i < N; i++) cin >> A[i] >> B[i] >> C[i];

  fill_n(*dp, 300 * 300, -1);
  for(int i = 0; i < N; i++) {
    if(B[i] >= T[0] && T[0] >= A[i]) dp[0][i] = 0;
  }

  for(int i = 1; i < D; i++) {
    for(int j = 0; j < N; j++) {
      if(~dp[i - 1][j]) {
        for(int k = 0; k < N; k++) {
          if(B[k] >= T[i] && T[i] >= A[k]) {
            dp[i][k] = max(dp[i][k], dp[i - 1][j] + max(C[j] - C[k], C[k] - C[j])); 
          }
        }
      }
    }
  }
  cout << *max_element(dp[0], dp[300]) << endl;
}

Measured memory_bytes: 1512
var fs = require('fs'),
    length = fs.fstatSync(process.stdin.fd).size,
    buffer = new Buffer(length),
    bytesRead = fs.readSync(process.stdin.fd, buffer, 0, length, 0),
    input = buffer.toString('utf8', 0, bytesRead).split('\n');
main();
function main(){
var num = parseInt(input);
var answer = num * num * num ;
console.log(answer);
}


Measured memory_bytes: 15416
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

const int64_t S = 1e+4;

int64_t pow5(int64_t x) {
  int64_t y = x * x, z = y * y;
  return x * z;
}

struct SetItem
{
  int64_t k, v;
  SetItem(int64_t k) : k(k) { v = pow5(k); }
  SetItem(int64_t k, int64_t v) : k(k), v(v) {}
  bool operator<(const SetItem &item) const { return v < item.v; }
};

int main()
{
  int64_t X;
  cin >> X;

  set<SetItem> s;
  for (int64_t x = -S; x <= S; ++x) {
    s.emplace(x);
  }

  for (int64_t A = 0; A <= 1e+4; ++A) {
    auto itr = s.find(SetItem(12345, pow5(A) - X));
    if (itr != s.end()) {
      cout << A << ' ' << itr->k << endl;
      break;
    }
  }

  return 0;
}

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

#define ff first
#define ss second
#define pb push_back
#define ll long long
#define ull unsigned long long
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mst(ss,b) memset(ss,b,sizeof(ss));
#define dbg(x) cout << #x << "= " << x << endl;
typedef pair <int, int> pii;
const int inf = 0x3f3f3f3f;
const ll INF = (1LL<<62)-1;
const ll mod = 1e9+7;
const int N = 1e5+5;

vector<pii >tx, ty;
int n, m, x[N], y[N];
int p[N];    //并查集的使用

const int maxm = 5e5+5;

struct edge{
    int u,v;
    ll cost;
    bool operator < (const edge& rhs)const {
        return cost < rhs.cost;
    }
}e[maxm];

int Find(int x){//查找x的父亲节点，递归调用
    return  p[x]==x?x:p[x]=Find(p[x]);
}

ll kruskal(int n,int m){  //返回最小生成树的权值
    ll ans=0;
    sort(e,e+m);
    for(int i=0 ; i<m ; i++){
        int u=e[i].u;
        int v=e[i].v;
        u=Find(u);
        v=Find(v);
        if(u!=v){   //如果不在一个集合中，合并
            ans+=e[i].cost;
            p[v]=u;
        }
    }
    return ans;
}

void addedge(int u, int v){
    e[m].u = u, e[m].v = v, e[m++].cost = min(abs(x[u]-x[v]), abs(y[u]-y[v]));
}

int  main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++)p[i] = i;
    for(int i=1; i<=n; i++){
        scanf("%d%d", &x[i], &y[i]);
        tx.pb({x[i], i});
        ty.pb({y[i], i});
    }
    sort(tx.begin(), tx.end());
    sort(ty.begin(), ty.end());
    for(int i=0; i<n-1; i++){
        addedge(tx[i].ss, tx[i+1].ss);
        addedge(ty[i].ss, ty[i+1].ss);
    }
    printf("%lld\n", kruskal(n, m));
    return 0;
}


//    lower_bound()
//    __builtin_popcount()
//    ios::sync_with_stdio(false);
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
//    const double eps=1e-12;
//    #pragma comment(linker,"/STACK:102400000,102400000")



Measured memory_bytes: 8940
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int N; 
int A[200010];
int binary_search(int key) {
    int left = 0, right = N - 1; // 配列 a の左端と右端
    while (right >= left) {
        int mid = left + (right - left) / 2; // 区間の真ん中
        if (A[mid] == key) return mid;
        else if (A[mid] > key) right = mid - 1;
        else if (A[mid] < key) left = mid + 1;
    }
    return -1;
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    int k = (1<<30);
    map<int, int> cnt;
    rep(i, N) cnt[A[i]]++;
    int ans = 0;
    while(k >= 1) {
        rrep(i, N - 1) {
            //cout << A[i] << endl;
            int idx = binary_search(k - A[i]);
            if (idx != -1 && cnt[A[i]] >= 1 && ((A[i] != A[idx] && cnt[A[idx]] >= 1) || (A[i] == A[idx] && cnt[A[i]] >= 2))) {
                //cout << A[i] << " " << A[idx] << endl;
                cnt[A[i]]--; cnt[A[idx]]--;
                ans++;
            }
        }
        k = k >> 1;
    }
    cout << ans << endl;


    return 0;
}


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

int main(){
  int n; cin>>n;
  long long b1=0,b2=0,b4=0;
  for(int i=0;i<n;i++){
    long long a; cin>>a;
    if(a%4==0)b4++;
    else if(a%2==0)b2++;
    else b1++;
  }
  if(b2>0)cout<<(b1<=b4 ? "Yes" : "No");
  else cout<<(b1<=b4+1 ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main() {

    int k, a, b,res=0;
    scanf("%d", &k);
    scanf("%d %d", &a, &b);

    res = a / k;
    res *= k;
    res += k;

    if(res < b || b % k == 0 || a % k == 0) {
        printf("OK");
    } else {
        printf("NG");
    }
}

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

int main(int argc, char const *argv[]) {
  int n, ans;
  cin >> n;

  for (size_t i = 1; i <= 64; i *= 2) {
    if (i <= n) ans = i;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n;
string s;
int ct[N], sz[N];
vector<int> adjlist[N];
int hi[N], lo[N];
void dfs(int u, int p){
    hi[u] = lo[u] = 0;
    sz[u] = ct[u];
    for (auto v : adjlist[u]){
        if (v == p) continue;
        dfs(v,u);
        sz[u] += sz[v];
        hi[v] += sz[v];
        lo[v] += sz[v];
        hi[u] += hi[v];
    }
    int mx = 0;
    int mxh = 0;
    for (auto v : adjlist[u]){
        if (v == p) continue;
        if (hi[v] > mxh){
            mxh = hi[v];
            mx = lo[v];
        }
    }
    if (mx <= hi[u]-mxh){
        ///Can distribute
        lo[u] = hi[u]%2;
    }
    else lo[u] = mx-(hi[u]-mxh);
}
int main(){
    scanf("%d",&n);
    cin >> s;
    for (int i = 1; i <= n; i++){
        ct[i] = s[i-1]-'0';
    }
    for (int i = 1; i < n; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    int ans = -1;
    for (int i = 1; i <= n; i++){
        dfs(i,-1);
        for (int j = 1; j <= n; j++){
            //printf("%d %d %d %d\n",i,j,hi[j],lo[j]);
        }
        if (hi[i] % 2 == 0 && lo[i] == 0){
            //printf("CAN\n");
            if (ans == -1 || ans > hi[i]/2) ans = hi[i]/2;
        }
    }
    printf("%d\n",ans);


}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a;
	cin >> b;

	int sum = 0;

	b = b - a;

	for (int i = 0; i < b; i++) {
		sum = sum + i;
	}

	sum = sum - a;

	cout << sum;

	cin >> a;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int H, W;
	
	cin >> H >> W;

	string s[H];

	rep(i, H)
	{
		cin >> s[i];
	}

	char output[H+2][W+2];

	for (int i = 0; i < H + 2; i++)
	{
		for (int j = 0; j < W + 2; j++)
		{
			if ((i == 0) || (j == 0) || (i == H + 1) || (j == W + 1))
			{
				output[i][j] = '#';
			}
			else 
			{
				output[i][j] = s[i-1][j-1];
			}
		}
	}

	for (int i = 0; i < H + 2; i++)
	{
		for (int j = 0; j < W + 2; j++)
		{
			cout << output[i][j];
		}

		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, t; cin >> n >> t;
	vector<pair<int, int>> c(n);
	rep(i, 0, n - 1)cin >> c[i].first >> c[i].second;
	sort(all(c));
	vector<vector<int>> dp(6100, vector<int>(6100, 0));
	rep(i, 0, n - 1)rep(j, 0, t - 1)
	{
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		if (c[i].first + j < t)
		{
			dp[i + 1][j + c[i].first] = max(dp[i][j + c[i].first], dp[i][j] + c[i].second); 
		}
	}
	int ans = 0;
	rep(i, 0, n - 1)ans = max(ans, dp[i][t - 1] + c[i].second);
	cout << ans << endl;
}


Measured memory_bytes: 145920
# B - Counting Roads
N, M = map(int,input().split())
city = [list(map(int, input().split())) for i in range(M)]
road = [0]*N

for i in range(N):
    count = 0
    for j in range(M):
        if i+1 == city[j][0]:
            count += 1
        else:
            pass
        if i+1 == city[j][1]:
            count += 1
        else:
            pass
    road[i] = count
for k in range(N):
    print(road[k])


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  while(1){
    int y,m,d;
    string g;
    
    cin>>g>>y>>m>>d;
    
    if(g=="#")
      break;

    if(y>31 || (y==31 && m>=5)){
      cout<<"?"<<" "<<y-30<<" "<<m<<" "<<d<<endl;
    }
    else{
      cout<<"HEISEI"<<" "<<y<<" "<<m<<" "<<d<<endl;
    }
  }
}



Measured memory_bytes: 3216
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll n;
cin>>n;
ll ans=infll;
for(int i=1;i<=pow(10,6);i++){
    if(n%i==0){
    chmin(ans,i+n/i);
    }
}
cout<<ans-2<<endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector <int> x(N);
  vector <int> y(N);
  vector <int> h(N);
  bool flag        = true;
  int Hs[101][101] = { };
  for (int i = 0; i < N; i++) {
	  cin >> x[i] >> y[i] >> h[i];
	  if (flag && h[i] > 0) {
		  for (int k = 0; k < 101; k++) {
			  for (int l = 0; l < 101; l++) {
				  Hs[k][l] = h[i] + abs(x[i] - k) + abs(y[i] - l);
				}
			}
		  flag = false;
		}
	}
  for (int k = 0; k < 101; k++) {
	  for (int l = 0; l < 101; l++) {
		  flag = true;
		  for (int i = 0; i < N; i++) {
			  if (h[i] != max(0, Hs[k][l] -  abs(x[i] - k) - abs(y[i] - l))) {
				  flag = false;
				  break;
				}
			}
		  if (flag) {
			  cout << k << " " << l << " " << Hs[k][l] << endl;
			  return 0;
			}
		}
	}
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int N,M,p;
vector<int>D;
int pdist(int s,int t){return(t>=s)?(t-s):((t+N)-s);}
int ndist(int s,int t){return pdist(t,s);}

int solve(){
	if(D.size()==1)return min(pdist(D[0],p),ndist(D[0],p));
	int ans=2*N;
	for(int i=0;i<M;i++){
		int b=D[i];
		int e=D[(i+1)%M];
		int d=min(pdist(b,p),min(pdist(e,p),min(ndist(b,p),ndist(e,p))));
		ans=min(d+(N-pdist(b,e)),ans);
	}
	return ans;
}
int main(){
	int k;
	cin>>N>>M>>p;

	for(int i=0;i<M;i++){
		cin>>k;

		D.push_back(k);
	}
	sort(D.begin(),D.end());
	cout<<100*solve()<<endl;
    return 0;
}

Measured memory_bytes: 1324