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

#define FOR(i,l,r) for(int i = int(l);i < int(r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
const int MAX_N = 100000;
vector< pair<ll,int> > G [MAX_N];
int subSize [MAX_N],par [MAX_N];
ll minCost [MAX_N];
const int INF = 1e9;
const ll INFLL = 1e18;

void get_size(int curr,int prev)
{
	subSize [curr] = 1;
	for(const auto& it : G [curr]) if(it.second != prev){
		get_size(it.second,curr);
		par [it.second] = curr;
		subSize [curr] += subSize [it.second];
	}
}

void dfs(int curr,int prev,ll cost)
{
	minCost [curr] = cost;
	for(const auto& it : G [curr]) if(it.second != prev){
		dfs(it.second,curr,cost + it.first);
	}
}

int main()
{
	scanf("%d",&N);
	FOR(i,0,N - 1){
		int a,b;
		ll c;
		scanf("%d%d%lld",&a,&b,&c);
		a--;
		b--;
		G [a].push_back(make_pair(c,b));
		G [b].push_back(make_pair(c,a));
	}

	get_size(0,-1);
	int mn = INF,id = -1;
	FOR(i,0,N){
		int x = N,mx = 0;
		for(const auto& it : G [i]) if(it.second != par [i]){
			chmax(mx,subSize [it.second]);
			x -= subSize [it.second];
		}
		if(chmin(mn,max(x,mx))){
			id = i;
		}
	}

	fill(minCost,minCost + N,INFLL);
	minCost [id] = INFLL;
	bool flag = true;
	ll ans = 0;
	{
		int x = N - 1,mx = 0;
		for(const auto& it : G [id]){
			dfs(it.second,id,it.first);
			if(it.second != par [id]){
				chmax(mx,subSize [it.second]);
				x -= subSize [it.second];
			}
		}
		chmax(mx,x);
		if(mx > N - 1 - mx){
			for(const auto& it : G [id]) if(it.second != par [id]){
				if(subSize [it.second] == mx){
					ans -= it.first;
					flag = false;
					break;
				}
			}
			if(flag) for(const auto& it : G [id]) if(it.second == par [id]){
				ans -= it.first;
				flag = false;
				break;
			}
		}
	}
	FOR(i,0,N) if(i != id){
		ans += minCost [i] * 2;
	}
	if(flag){
		ans -= *min_element(minCost,minCost + N);
	}

	printf("%lld\n",ans);

	return 0;
}


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

int main(void){
 int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;
   int x3 = x2 - (y2 - y1);
    int y3 = y2 + x2 - x1;
    int x4 = x3 - (x2 - x1);
    int y4 = y3 - (y2 - y1);
   
    cout << x3 <<" "<< y3 <<" "<< x4 <<" "<< y4;

  return 0;
}

Measured memory_bytes: 384
n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')
for j in range(n):
    for i in range(j):
        k = j+(j-i)
        if k < n:
            if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]:
                continue
            ans -= 1

print(ans)

Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <map>
using namespace std;
constexpr int mod = 1e9 + 7;

int64_t modinv(int64_t a)
{
    int64_t b = mod, u = 1, v = 0;
    while (b)
    {
        int64_t t = a / b;
        a -= t * b;
        b += a, a = b - a, b -= a;
        u -= t * v;
        v += u, u = v - u, v -= u;
    }
    u %= mod;
    if (u < 0)
        u += mod;
    return u;
}

map<int64_t, int> prime_factor(int64_t n)
{
    map<int64_t, int> ret;
    for (int64_t i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    map<int64_t, int> facts;
    facts = prime_factor(a[0]);
    for (int i = 1; i < n; i++)
    {
        map<int64_t, int> tmp;
        tmp = prime_factor(a[i]);
        auto itr = tmp.begin();
        for (; itr != tmp.end(); itr++)
        {
            facts[itr->first] =
                facts[itr->first] > itr->second ? facts[itr->first] : itr->second;
        }
    }
    int64_t ans = 0LL, lcm = 1LL;
    for (auto itr = facts.begin(); itr != facts.end(); itr++)
    {
        for (int i = 0; i < itr->second; i++)
        {
            lcm *= itr->first;
            lcm %= mod;
        }
    }
    for (int i = 0; i < n; i++)
    {
        int64_t res = (lcm * modinv(a[i])) % mod;
        ans += res;
        ans %= mod;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

const string YES = "Yes";
const string NO = "No";
template<class T> void YesNo(T a) {cout<<(a?YES:NO)<<endl;}

void solve(std::string S){
    YesNo(S!="AAA" && S!="BBB");
} 

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$A = explode(" ", trim(fgets(STDIN)));
$total = array_sum($A);
$ans = PHP_INT_MAX;
$X = 0;
for ($i = 1; $i < $N; $i++) {
    $X += $A[$i - 1];
    $Y = $total - $X;
    $ans = min($ans, abs($X - $Y));
}
echo $ans;


Measured memory_bytes: 23200
#include <stdio.h>
//#include <string.h>

int main() {
    int r, c, i, j, val, rowSum = 0, rowInc = 0, colInc = 0, sum = 0;

    scanf("%d %d", &r, &c);

    int rowSums[r], colSums[c];

    memset(colSums, 0, c*sizeof(int));

    int in[r][c];

    for (i = 0; i < r; ++i) {
        for (j = 0; j < c; ++j) {
            scanf("%d", &val);
            rowSum += val;

            in[i][j] = val;

            colSums[j] += val;
            //printf("adding %d to colsums[%d]\n", val, j);
        }
        rowSums[i] = rowSum;
        rowSum = 0;
    }

    for (i = 0; i < r+1; ++i) {
        for (j = 0; j < c+1; ++j) {
            if (i == r) {
                if (j == c)
                    printf("%d\n", sum);
                else {
                    sum += colSums[colInc];
                    printf("%d ", colSums[colInc++]);
                }
            } else if (j == c)
                printf("%d\n", rowSums[rowInc++]);
            else
                printf("%d ", in[i][j]);
        }
    }

    return 0;
}


Measured memory_bytes: 2024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin>>n>>m;
  vector<string> as(n),bs(m);
  for(int i=0;i<n;i++){cin>>as.at(i);}
  for(int i=0;i<m;i++){cin>>bs.at(i);}
  for(int i=0;i<n+1-m;i++){
    for(int j=0;j<n+1-m;j++){
      int matches=0;
      for(int k=0;k<m;k++){
        for(int l=0;l<m;l++){
          if(as.at(i+k).at(j+l)==bs.at(k).at(l)){matches++;}
        }
      }
      if(matches==m*m){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c;
  scanf("%d%d",&a,&b);

  if(a < b){
    c = a;
    a = b;
    b = c;
  }

  while(b != 0){
    c = a % b;
    a = b;
    b = c;
  }
  printf("%d\n",a);

  return 0;
}
  

Measured memory_bytes: 592
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main(){
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

    let xxx = read::<String>(s).unwrap();
	let mut n = 0;	
	if xxx == "SSS" { n = 0 }
	if xxx == "SSR" { n = 1 }
	if xxx == "SRS" { n = 1 }
	if xxx == "SRR" { n = 2 }
	if xxx == "RSS" { n = 1 }
	if xxx == "RSR" { n = 1 }
	if xxx == "RRS" { n = 2 }
	if xxx == "RRR" { n = 3 }
	println!("{}", n);
}


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

int main(){
  int A,B,K;

  cin >> A >> B >> K;
  int sum = K;
  for(int i = min(A,B); i >= 1; i--){
    if(A % i == 0 && B % i == 0){
      sum--;
    }
    if(sum == 0){cout << i; return 0; }
  }

  
  return 0;
}

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cout<<#x<<" = "<<x<<endl;

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    string s;

    cin>>s;

    if(s=="RRR")
    {
    	cout<<3;
    }
    else if(s=="RRS" || s=="SRR")
    {
    	cout<<2;
    }
   	else if(s=="SSS")
   		cout<<0;
   	else
   		cout<<1;

}

int main()
{    
    

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

    li t=1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long x1,y1,x2,y2;
  cin >> x1>>y1>>x2>>y2;
  cout << x2-(y2-y1) <<" "<< y2+(x2-x1) <<" "<< x1-(y2-y1) <<" "<< y1+(x2-x1) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int t; cin>>t; while(t--)
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll c,d,e,f,i,j,k,l;
    string a;
    cin>>a;
    if(a.size()==2)
    {
        if(a[0]==a[1])
        {
            cout<<"1 2"<<endl;
        }
        else cout<<"-1 -1"<<endl;
    }
    else
    {
        for(i=0; i<a.size()-2; i++)
        {
            if(a[i]==a[i+1])
            {
                cout<<i+1<<" "<<i+2<<endl;
                return 0;
            }
            if(a[i]==a[i+2])
            {
                cout<<i+1<<" "<<i+3<<endl;
                return 0;
            }
            if(a[i+1]==a[i+2])
            {
                cout<<i+2<<" "<<i+3<<endl;
                return 0;
            }
        }
        cout<<"-1 -1"<<endl;

    }

    return 0;
}


Measured memory_bytes: 3764
#include <stdio.h>

int main()
{
  int N, T;
  int c[101];
  int t[101];

  int min = 100;
  c[min] = 100000000;
  scanf("%d %d", &N, &T);
  for (int i = 0; i < N; i++) {
    scanf("%d %d", &c[i], &t[i]);
    if (t[i] <= T && c[i] < c[min])
      min = i;
  }
  if (min == 100)
    puts("TLE");
  else
    printf("%d\n", c[min]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  string a,b; cin >> a >> b;
  int x = stoi(a + b);
  if(x % (int)sqrt(x) == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    if N % K == 0:
        ret = 0
    else:
        ret = 1
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

struct Combination {
    vector<ll> fac, finv, inv;
    const int mod = 1e9 + 7;
    
    Combination(int n) : fac(n + 1), finv(n + 1), inv(n + 1) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        
        for (int i = 2; i < n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    
    ll nCr(int n, int k) {
        if ((n < k) || (n < 0) || (k < 0)) {
            return 0;
        }
        
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int mod = 1e9 + 7;
    int h, w, a, b;
    Combination c(max(h, w));
    cin >> h >> w >> a >> b;
    ll ans = 0;
    reps(i, b, w) {
        ans = (ans + c.nCr(i + (h - a - 1), i) * c.nCr((a - 1) + (w - i - 1), (a - 1)) % mod) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 147840
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll x,y;
    cin>>x>>y;
    int cnt=0;
    while(1){
        x=x*2;
        cnt++;
        if(x>y)break;
    }
    cout<<cnt<<endl;


    return 0;
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    char c ; cin >> c ; 
    
    if ( c == 'A' ) cout << "T" ; 
    else if ( c == 'T' ) cout << "A" ; 
    
    else if ( c == 'G' ) cout << "C" ; 
    else cout << "G" ; 
    
}   

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int calc(string s){
	s += '!';
	int n = s.length(),cnt = 1,ans = 0;
	for(int i = 1;i < n;i++){
		if(s[i] == s[i - 1]) cnt++;
		else{
			ans += cnt / 2;
			cnt = 1;
		}
	}
	return ans;
}

signed main(){
	int k;
	set<char> st;
	string s;
	cin >> s >> k;
	for(int i = 0;i < s.length();i++) st.insert(s[i]);
	if(st.size() == 1){
		cout << s.length() * k / 2 << endl;
		return 0;
	}
	int a = calc(s),b = calc(s + s);
	cout << a + (b - a) * (k - 1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

    int a, b;
    int i;

    for(i = 0; 1; i++){
        scanf("%d %d", &a, &b);
        if(a == 0 && b == 0) break;

        if(a < b) printf("%d %d\n", a, b);
        else      printf("%d %d\n", b, a);

   }
   return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
const int N = 155;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

int f[2][N];
int g[2][N][N][N];
int n,K,m;

inline void add(int &x,int y){
   x += y; if(x >= m)x -= m;
}

int main(){
   scanf("%d%d%d",&n,&K,&m);
   if(K%2 == 0){
      int ans = 1;
      fr(t,0,1){
         int len = (n+t)/2;
         int cur = 0;
         memset(f,0,sizeof f);
         f[0][0] = 1;
         fr(z,1,len){
            cur ^= 1;
            memset(f[cur],0,sizeof f[cur]);
            fr(j,0,K/2){
               if(j < K/2)add(f[cur][j+1],f[cur^1][j]);
               add(f[cur][0],f[cur^1][j]);
            }
         }
         int res = 0;
         fr(z,0,len)add(res,f[cur][z]);
         ans = 1LL*ans*res%m;
      }
      printf("%d\n",ans);
   } else {
      int cur = 0;
      g[0][0][0][n] = 1;
      
      int ans = 0;
      fr(i,1,n){
         cur ^= 1; memset(g[cur],0,sizeof g[cur]);
         int odd = i/2,even = (i+1)/2;
         fr(j,0,even){
            fr(k,0,odd){
               fr(t,i-1,n){
                  int to = (t%2 != i%2) ? n : t;
                  add(g[cur][0][j][to],g[cur^1][j][k][t]);
                  if(t != i-1){
                     to = t;
                     if(j*2 > K)to = min(to,i-k*2+K-1);
                     add(g[cur][k+1][j][to],g[cur^1][j][k][t]);
                  }
               }
            }
         }
      }

      fr(j,0,n){
         fr(k,0,n){
            add(ans,g[cur][j][k][n]);
         }
      }
      printf("%d\n",ans);
   }
   return 0;
}


Measured memory_bytes: 29440
#include <bits/stdc++.h>
using namespace std;
 
int n = 0;
char str[3]; 
 
int main(){
  int i;
  cin>> str;
  for(i=0;i<4;++i){
    if(str[i] == '+') ++n;
    else if(str[i] == '-') --n;
  }
  cout<< n <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define LL long long
#define inf 1000000007
using namespace std;
LL quick_mod(LL a, LL b)
{
    LL ans = 1;
    a %= inf;
    while(b)
    {
        if(b & 1)
        {
            ans = ans * a % inf;
            b--;
        }
        b >>= 1;
        a = a * a % inf;
    }
    return ans;
}

LL C(LL n, LL m)
{
    if(m > n)
        return 0;
    LL ans = 1;
    for(int i=1; i<=m; i++)
    {
        LL a = (n + i - m) % inf;
        LL b = i % inf;
        ans = ans * (a * quick_mod(b, inf-2) % inf) % inf;
    }
    return ans;
}

LL Lucas(LL n, LL m)
{
    if(m == 0)
        return 1;
    return C(n % inf, m % inf) * Lucas(n / inf, m / inf) % inf;
}

ll pow1(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b%2)
            (res*=a)%=inf;
        (a*=a)%=inf;
        b/=2;
    }
    return res;
}
int main()
{
    int n;
    ll a[200],ans=0,ans1=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%lld",&a[i]),ans+=a[i],ans1+=(a[i]*a[i]);
    if(ans%n==0)
        printf("%lld",ans1-ans*ans/n);
    else
    {
        ll tmp=ans/n,tmp1=ans/n+1;
        printf("%lld",min(n*tmp*tmp-2*tmp*ans+ans1,n*tmp1*tmp1-2*tmp1*ans+ans1));
    }
return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

before = H[0]
for i in range(1, N):
    h = H[i]
    if h > before:
        H[i] -= 1
    elif h < before:
        print('No')
        exit()
    
    before = H[i]

print('Yes')

Measured memory_bytes: 14252
#include<stdio.h>

int main(void){
    int h,w;
    scanf("%d%d", &h,&w);

    char s[h][w+1];
    for(int i=0; i<h; i++){
        scanf("%s", s[i]);
    }
    
    int dx[4] = {1,-1,0,0};
    int dy[4] = {0,0,1,-1};
    int tmpx,tmpy;

    int flag_ans = 1;
    int flag_part = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            
            if(s[i][j] == '#'){
                flag_part = 0;
                for(int k=0; k<4; k++){
                    tmpx = i+dx[k];
                    tmpy = j+dy[k];

                    if((0<=tmpx)&&(tmpx<h)){
                        if((0<=tmpy)&&(tmpy<w)){
                            if(s[tmpx][tmpy] == '#'){
                                flag_part = 1;
                            }
                        }
                    }
                }

                if(flag_part == 0){
                    flag_ans = 0;
                    goto loopend;
                }
            }
        }
    }

    loopend:
    if(flag_ans == 1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 128
n = int(input())
a = [int(x) for x in input().split()]


def calc(sign):
    r = 0
    b = [None] * n
    for i in range(n):
        if i % 2 == sign:
            if r + a[i] > 0:
                b[i] = a[i]
            else:
                b[i] = - r + 1
        else:
            if r + a[i] < 0:
                b[i] = a[i]
            else:
                b[i] = - r - 1
        r += b[i]
    return b


ans = float('inf')
for sign in [0, 1]:
    b = calc(sign)
    d = 0
    for i in range(n):
        d += abs(a[i] - b[i])
    ans = min(ans, d)
print(ans)


Measured memory_bytes: 14468
#include "bits/stdc++.h"
#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

int main() {
    fastIO;
    int t;
    cin >> t;

    cout << !t;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

	int x, n;
	cin>>x>>n;
	vector<int> pn;
	bool a = false;
	
	for(int i = 0; i<n; i++)
	{
		int temp;
		cin >> temp;
		pn.push_back(temp);
	}
	if(find(pn.begin(), pn.end(), x)==pn.end())
	{
		cout<<x;
		a=true;
	}
	if(!a)
	{
		for(int i = 1; i<=100; i++)
		{
			if(find(pn.begin(), pn.end(), x-i)==pn.end())
			{
				cout<<x-i;
				break;
		    }
			if(find(pn.begin(), pn.end(), x+i)==pn.end())
			{
				cout<<x+i;
		    	break;
		    }
		}
	}
	
	
	return 0;
}

Measured memory_bytes: 3652
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n;
string t;
int m = 1;
vector<int> res;
void bt(int ak,int naco,string& z,int mn){
  if(mn == m){
    res[ak]=naco;
    return;
  }
  R(i,3){
    int mam = i;
    string zm;
    for(char x:z){
      if(x == 'R'){
        mam++;
        if(mam == 3){
          mam = 0;
          zm += 'R';
        }
      }else{
        if(mam >= 1)mam = 3 - mam;
        if(SZ(zm) && zm.back() == 'S')
          zm.pop_back();
        else
          zm += 'S';
      }
    }
    bt(ak + i * mn, naco + mam * mn, zm, mn*3);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> t;
  R(_,n)m *= 3;
  res.resize(m);
  bt(0,0,t,1);
  R(i,m){
    cout << res[i] << " ";
  }
  cout << "\n";
}


Measured memory_bytes: 8464
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n;
    cin >> n;
    int arr[n+1];
    memset(arr, 0, sizeof(arr));
    for(int x=1; n>=x*x; x++){
        for(int y=1; n>=y*y; y++){
            for(int z = 1; n>=z*z; z++){
                if(x*x + y*y + z*z + x*y + z*y + x*z <= n){
                    arr[x*x + y*y + z*z + x*y + z*y + x*z]++;
                }
            }
        }
    }
    for(int i=1; n>=i; i++){
        cout << arr[i] << endl;
    }
}






Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int ans1 = min(a,b);
  int ans2;
  if(a+b-n<=0){
    ans2 = 0;
  } else {
    ans2 = a+b-n;
  }
  cout << ans1 << " " << ans2 << endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ervb
//
//  Created by Kanak Gautam on 21/04/20.
//  Copyright © 2020 Kanak Gautam. All rights reserved.
//
 
 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
using namespace std;
typedef long long int lli;
typedef long double ld;
priority_queue <lli, vector<lli>, greater<lli> > ti;
vector <lli> p[500005],g,b(500005,0),f(500005,0);
vector <ld> a(200005);
lli vis[200005];
map <pair<lli,lli>,lli> mp;
set<pair<lli, lli> > s;
set<lli> st;
map<lli,lli> np,v;
queue<lli> qy;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
lli fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
    return f[i];
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
bool cmp(lli i,lli j)
{
    return p[i].size()<p[j].size();
}
/*void sieve()
{
    for(lli i=2;i<=5000000;i++)
    {
        if(b[i]==0)
        {
        for(lli j=2;i*j<=5000000;j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    lli n;cin>>n;
    ld x;
    
    for(lli i=0;i<n;i++)
    {
        cin>>x;
        lli h=llround(x*1e9);
        //cout<<x<<" "<<h<<endl;
        lli t=0,f=0;
        while(h%2==0 && h>0)
        {
            t++;
            h/=2;
        }
        while(h%5==0 && h>0)
        {
            f++;
            h/=5;
        }
        mp[{t,f}]++;
    }
    lli ans=0;
    for(auto u:mp)
    {
        for(auto v:mp)
        {
            if(u.first.first+v.first.first>=18 && u.first.second+v.first.second>=18)
            {
                if(u>v)
                    ans+=u.second*v.second;
                if(u==v)
                    ans+=(u.second*(u.second-1))/2;
            }
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 25712
#include <stdio.h>
#include <limits.h>
#include<string.h>
#include <math.h>

int main(){
    int n;
    scanf("%d", &n);
    int a[3] ={0};
    for(int i=0;i<n;i++){
        int j;
        scanf("%d", &j);
        if(j%4 == 0) a[2] ++;
        else if( j%2 ==0) a [1]++;
        else a[0]++;
    }
    if(a[0]<=a[2]) printf("Yes");
    else if(a[0]==a[2]+1 && a[1]==0) printf("Yes");
    else printf("No");

}


Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n,a[100],i,j,max,t,alice=0,bob=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
      max=0;
    for(j=0;j<n;j++){
      if(max<a[j]){
        max=a[j];
        t=j;
      }
    }
    if(i%2==0){
      alice+=max;
    }else{
      bob+=max;
    }
    a[t]=0;
  }
  printf("%d\n",alice-bob);
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T>
struct BIT{
    //1-index
    //0-indexで取ると無限ループする
    private:
    V<T> arr;
    int n;

    public:
    BIT(int siz){
        n=siz;
        arr.assign(n+1,0);
    }
    //一点更新 aにvを加える
    void add(T a,T v){
        //x+=(x&-x) 初項a,それ以降a<=2^Nが列挙
        for(T x=a;x<=n;x+=(x&-x)){
            arr[x]+=v;
        }
    }
    T sum(T a){
        // 1からaまでの区間和
        T ret=0;
        for(T x=a;x>0;x-=(x&-x))ret+=arr[x];
        return ret;
    }
    T get(T x){//x番目に大きい数　// 区間和がw以上となる最小のindを返す
        if(x<=0) return 0;
        T N=1;
        while(N*2<=n)N*=2;
        T v=0;
        for(T i=N;i>0;i/=2){
            if(v+i<=n&&arr[v+i]<x){
                x-=arr[v+i];
                v+=i;
            }
        }
        return v+1;
    }
    T query(int l,int r){
        return sum(r)-sum(l);
    }
};
int main(){
  int n,k;
  cin>>n>>k;
  V<int> d(n+1);
  for(int i=1;i<=n;i++)cin>>d[i];
  for(int i=0;i<k;i++){
     BIT<int> a(400005),b(400005);
     V<int> cp(n+1,INT_MAX);
     for(int j=1;j<=n;j++){
         a.add(j+d[j],1);
         cp[j]=a.query(j-1,400005);
     }    
     for(int j=n;j>=1;j--){
       cp[j]+=b.query(0,j);
       b.add(max(j-d[j],1),1);
     }
     d=cp;
     if(n==*min_element(all(d))){
      // cout<<i<<"\n";
       break;
     }
  }
  for(int j=1;j<=n;j++)cout<<d[j]<<" \n"[j==n];
}


Measured memory_bytes: 7952
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> mochi(N);

    for (auto &card : mochi)
        std::cin >> card;
    
    std::sort(mochi.begin(), mochi.end());
    mochi.erase(std::unique(mochi.begin(), mochi.end()), mochi.end());

    std::cout << mochi.size();

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

int main(){
	int a,b;
	cin>>a>>b;
	int ans=0;
	while(a*ans-ans+1<b){
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdinLock};
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let n: usize = sc.read();
    println!("{}", n / 3);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s;
    cin >> s;
    string t[3] = {"Sunny", "Cloudy", "Rainy"};
    rep(i,3) {
        if (s == t[i]) {
            cout << t[(i+1)%3] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
  int n[1000000]={0};
  int i,j;

  for(i=2;i<=999999;i++){
    for(j=2;j<=(int)sqrt((double)i);j++){
      if(i%j == 0)
	break;
      if(j==(int)sqrt((double)i) && i%j!=0)
	n[i]=1;
    }
  }

  n[2]=1;
  n[3]=1;

  int k,l;
  while(scanf("%d", &k) != EOF){
    int m=0;
    for(l=2;l<=k;l++){
      if(n[l]==1)
	m++;
    }
    printf("%d\n",m);
  }
  return 0;
}

Measured memory_bytes: 6616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long LL;
struct X{
	LL A;
	int B;
	X(){
		A=0;
		B=0;
	}
};
bool Comp(X&r,X&l){
	if (r.A<l.A){
		return true;
	}else{
		return false;
	}
}
int main(int argc, char* argv[])
{
	int N,M;
	cin>>N>>M;
	vector<X> AB(N);
	int i;
	for (i=0;i<N;i++){
		cin>>AB[i].A>>AB[i].B;
	}
	sort(AB.begin(),AB.end(),Comp);
	LL ans=0;
	int SumB=0;
	for (i=0;i<N;i++){
		if (SumB==M){
			break;
		}
		if (SumB+AB[i].B<=M){
			SumB+=AB[i].B;
			ans+=AB[i].A*AB[i].B;
		}else{
			int x=M-SumB;
			SumB=M;
			ans+=AB[i].A*x;
		}
	}
	cout<<ans<<endl;	
	return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline

l = []
s = []

for i in range(5):
    l.append(int(input()))
    if l[-1] % 10 > 0:
        s.append( (l[-1] // 10 + 1) * 10 )
    else:
        s.append(l[-1])
        
idx = 0
min_ = 10
for i in range(5):
    x = l[i] % 10
    if min_ > x and x != 0:
        min_ = x
        idx = i

print(sum(s)-s[idx]+l[idx])

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

int main()
{
    long long k, n, a[210000],ans,dummy;
    cin >> k >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    ans = a[n-1] - a[0];
    for (int i = 0; i < n-1;i++){
        dummy = k - (a[i + 1] - a[i]);
        if(dummy <= ans){
            ans = dummy;
        }
    }
    cout << ans << endl;
}

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

int main(){
    int n,a;
    cin >> n;
    int ans[n];
    rep(i,n){
        cin >> a;
        ans[a-1] = i+1;
    }
    rep(i,n){
        cout << ans[i];
        if(i != n-1)cout << " ";
    }
}

Measured memory_bytes: 1152
n = int(input())
c = [[0] * 10 for _ in range(10)]
ans = 0
for i in range(1, n + 1):
    l = int(str(i)[0])
    r = i % 10
    c[l][r] += 1
for i in range(10):
    for j in range(10):
        ans += c[i][j] * c[j][i]
print(ans)

Measured memory_bytes: 3064
n = int(input())

t, a = input().strip().split(' ')
t, a = [int(t), int(a)]

h = map(int, input().split())
h = list(h)

min = 1000000
tmp = 1

def ave_tmp(x):
    return (t - x * 0.006)

def diff(ave_tmp):
    if (a - ave_tmp) > 0:
        return (a - ave_tmp)
    else:
        return (ave_tmp - a)

for i in range(len(h)):
    if diff(ave_tmp(h[i])) < min:
        min = diff(ave_tmp(h[i]))
        tmp = i + 1

print(tmp)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

vector<int> nums;

void BubbleSort(vector<int> A){
    int count = 0;
    int flag = 1;
    int j = 1;
    while(flag==1&&j<=A.size()-1){
        flag = 0;
        for(int i=0;i<A.size()-j;i++){
            if(A[i]>A[i+1]){
                swap(A[i], A[i+1]);
                flag = 1;
                count++;
            }
        }
        j++;
    }
    for(int i=0;i<A.size();i++){
        if(i==A.size()-1){
            cout << A[i] << endl;
            cout << count << endl;
            break;
        }
        cout << A[i] << " ";
    }

}

int main(){
    int n;
    cin >> n;
    nums.resize(n);
    
    for(int i=0;i<n;i++){
        cin >> nums[i];
    }

    BubbleSort(nums);

}


Measured memory_bytes: 3164
N = int(input())
S = str(N)
x = int(S[0])
y = int(S[1])
z = int(S[2])
if x > y:
    ans = x*100+x*10+x
elif x < y:
    x += 1
    ans = x*100+x*10+x
else:
    if x > z:
        ans = x*100+x*10+x
    elif x < z:
        x += 1
        ans = x*100+x*10+x
    else:
        ans = N
print(ans)


Measured memory_bytes: 9068
N,K = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*(N-1)]
mod = 10**9+7

E = [[] for _ in [0]*N]
for a,b in AB:
    E[a-1].append(b-1)
    E[b-1].append(a-1)

ans = K
q = [0]
V = [False for _ in [0]*N]
V[0] = True
while q:
    qq = []
    for i in q:
        l = K-2+(i==0)
        for j in E[i]:
            if V[j]:continue
            ans = ans * l % mod
            if ans == 0:break
            qq.append(j)
            V[j] = True
            l -= 1
    q = qq
print(ans)

Measured memory_bytes: 44328
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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

#define NODE 100001
vector<vector<pair<ll,ll> > > v(NODE);
ll dist[NODE];
int route[NODE];
int dijkstra(int start){
	for(int i = 0;i < NODE;i++) {
    dist[i] = INF;
    route[i] = -1;
  }
	dist[start] = 0;
	priority_queue<P,vector<P>,greater<P> > pq;
	pq.push(make_pair(0,start));
	while(!pq.empty()){
		P now = pq.top();pq.pop();
		ll d = now.first;
		ll node = now.second;
		if(dist[node] < d)continue;
		for(int i = 0;i < v[node].size();i++){
			ll opp_n = v[node][i].first;
			ll opp_d = v[node][i].second;
			if(dist[opp_n] > d + opp_d){
				dist[opp_n] = d + opp_d;
				pq.push(make_pair(dist[opp_n],opp_n));
        route[opp_n] = node;
			}
		}
	}
}

bool mat[110][110];

int main()
{
  int N, M; cin >> N >> M;
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    v[a].PB(MP(b, c));
    v[b].PB(MP(a, c));
    mat[a][b] = mat[b][a] = true;
  }

  for (int i = 0; i < N; i++) {
    dijkstra(i);
    for (int j = i + 1; j < N; j++) {
      int k = j;
      while (k != i) {
        mat[k][route[k]] = mat[route[k]][k] = false;
        k = route[k];
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (mat[i][j]) ans++;
    }
  }
  cout << ans / 2 << endl;
  
	return 0;
}



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

int a[30];
int b[30];

int main() {
   fill(a, a+26, 1e5);

   int n;
   cin >> n;
   while (n--) {
      string s;
      cin >> s;
      fill(b, b+26, 0);
      for (char c : s) {
         b[c-'a']++;
      }
      for (int i = 0; i < 26; i++) {
         a[i] = min(a[i], b[i]);
      }
   }

   string ans = "";
   for (int i = 0; i < 26; i++) {
      ans += string(a[i], 'a'+i);
   }
   cout << ans << endl;

   return 0;
}

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

using Int = int;
using namespace std;

#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; };
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; };
template<class T> T th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

int main(){
	Int n;
	cin >> n;
	Int d[55], ds_[55], *ds = ds_ + 1;
	ds[-1] = 0;
	RC(i, n){
		cin >> d[i];
		ds[i] = ds[i - 1] + d[i];
	}
	Int ans = 0;
	RC(i, n - 1){
		ans += ds[i] * d[i + 1];
	}
	cout << ans << endl;
}


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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

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

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

int main() {
    lli N, M;
    cin >> N >> M;
    lli ans = 0;
    for (lli i = 1; i * i <= M; i++) {
        if (M % i == 0) {
            if (i >= N) {
                ans = max(ans, M / i);
            }
            if (M / i >= N) {
                ans = max(ans, i);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int h1, h2, k1, k2;
  int a, b, c, d;
  cin >> h1 >> h2 >> k1 >> k2;
  cin >> a >> b >> c >> d;

  int hiroshi = a * h1 + c * (h1 / 10) + b * h2 + d * (h2 / 20);
  int kenjiro = a * k1 + c * (k1 / 10) + b * k2 + d * (k2 / 20);

  if (hiroshi > kenjiro) {
    cout << "hiroshi" << endl;
  } else if (hiroshi < kenjiro){
    cout << "kenjiro" << endl;
  } else {
    cout << "even" << endl;
  }

  return 0;
}


Measured memory_bytes: 3108
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n,cnt=0;
	double d;
	cin >> n >> d;
	ll a, b;
	rep(i, n) {
		cin >> a >> b;
		ll tmp = a * a + b * b;
		if (sqrt(tmp) <= d)cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3772