akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
string s[55];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	string ans = "";
	for (char c = 'a'; c <= 'z'; c++) {
		ll mi = inf;
		ll count = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < s[i].size(); j++) {
				if (s[i][j] == c) {
					count++;
				}
			}
			mi = min(mi, count);
			count = 0;
		}
		for (int k = 0; k < mi; k++) {
			ans += c;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);i++)
#define urep(i,a,n) for(ll i = (a);i>=(n);i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
ll Power(ll a,ll x) {
	int num = a;
	rep(i, 1, x)num *= a;
	return num;
}
ll Factorial(ll num) {
	int ret = 1;
	rep(i, 2, num + 1)ret *= i;
	return ret;
}
ll N, ans;
string S;
vector<ll>A;
int main() {
	cin >> N;
	A.push_back(0);
	rep(i, 1, N+1) {
		ll a;
		cin >> a;
		A.push_back(A[i - 1] + a);
	}
	sort(all(A));
	int count = 0;
	rep(i, 1, N+1) {
		if (A[i] == A[i - 1]) {
			count++;
			ans += count;
		}
		else {
			count = 0;
		}
	}
	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 2420
import numpy as np

N = int(input())
A = np.array([input().split() for _ in range(N)], dtype=np.int64).reshape(N,N)

INF = 10**15
np.fill_diagonal(A, INF)

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        detour = np.min(A[i]+A[j])
        if detour > A[i][j]:
            ans+=A[i][j]
        elif detour < A[i][j]:
            print(-1)
            exit()
print(ans)


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

int main() {
   int N;
   cin >> N;
   int A[N],a[N];
   long long x=0;
   vector<vector<int>> X(N,vector<int>(32));
   vector<int> Y(32);
   for (int i=0; i<N; i++) {
       cin >> a[i];
       int y=a[i];
       for (int j=0; j<32; j++) {
           X[i].at(j)=y%2;
           if (i==0) Y[j]=y%2;
           y/=2;
       }
   }
   for (int i=0; i<N; i++) {
       if (i!=0) {
           for (int j=0; j<32; j++) {
               Y[j]=(X[i].at(j)+Y[j])%2;
           }
       }
   }
   for (int i=0; i<N; i++) {
       for (int j=0; j<32; j++) {
       X[i].at(j)=(Y[j]+X[i].at(j))%2;
       }
   }
   for (int i=0; i<N; i++) {
       int count=0;
       for (int j=0; j<32; j++) {
           if (X[i].at(j)==1) count+=pow(2,j);
       }
       cout << count ;
       if (i!=N-1) cout << ' ';
       else cout << endl;
   }
}

Measured memory_bytes: 36768
#include<bits/stdc++.h>
using namespace std;
const int N=10000005,P=998244353;
int n,inv[N];
int main()
{
	scanf("%d",&n);inv[1]=1;
	for(int i=2;i<=n;i++)inv[i]=1ll*(P-P/i)*inv[P%i]%P;
	int s=0;for(int i=0,c=1,p=1;i<n/2;i++){s=(s+1ll*c*p)%P;p=p*2%P;c=1ll*c*(n-i)%P*inv[i+1]%P;}
	int t=1;for(int i=1;i<=n;i++)t=3ll*t%P;t=(t-2ll*s%P+P)%P;printf("%d\n",t);return 0; 
}


Measured memory_bytes: 39296
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
    int n,k;
    string s,ans = {};
    char tmp;
    cin >> n;
    cin >> s;
    cin >> k;
    tmp = s[k-1];
    for(int i = 0;i < s.size();i++){
        if(s[i] == tmp)ans += tmp;
        else ans += '*';
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
int main() {
    int X, Y;
    cin >> X >> Y;
    rep(x, X+1) {
        if(2*x+4*(X-x)==Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3628
// Problem : D - Chat in a Circle
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout << #x << "=" << x << endl
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z)                                                       \
  cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define dbp(x) \
  cout << #x << "= {" << (x.first) << ", " << (x.second) << "}" << endl;
#define dbv(v)                         \
  {                                    \
    cout << #v << " : ";               \
    for (auto x : v) cout << x << ' '; \
    cout << endl;                      \
  }
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#define die(x) return cout << x << '\n', 0;

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

struct comp {
  bool operator()(pii p1, pii p2) {
    return min(p1.first, p1.second) < min(p2.first, p2.second);
  }
};

int32_t main() {
  fastio;
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  int testcases;
  testcases = 1;
  // cin>>testcases;

  while (testcases--) {
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i, 0, n - 1) cin >> vec[i];
    sort(vec.begin(), vec.end());
    priority_queue<pair<int, int>, vector<pair<int, int> >, comp> pq;
    int ans = vec[n - 1];
    pq.push({vec[n - 1], vec[n - 2]});
    pq.push({vec[n - 1], vec[n - 2]});
    // dbv(vec);
    for (int i = n - 3; i >= 0; i--) {
      pii p = pq.top();
      pq.pop();
      // dbp(p);
      ans += min(p.first, p.second);
      pq.push({p.first, vec[i]});
      pq.push({p.second, vec[i]});
    }
    cout << ans << '\n';
  }

  return 0;
}


Measured memory_bytes: 8988
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

int n, m;
vector<int> gph[100005];
int par[100005], pth[100005];

int dfs(int x){
	pth[x] = 1;
	int ret = x;
	for(auto &i : gph[x]){
		if(!pth[i]){
			par[i] = x;
			ret = dfs(i);
			break;
		}
	}
	return ret;
}

int main(){
	scanf("%d %d",&n,&m);
	for(int i=0; i<m; i++){
		int s, e;
		scanf("%d %d",&s,&e);
		gph[s].push_back(e);
		gph[e].push_back(s);
	}
	int s = dfs(1);
	int e = 1;
	for(auto &j : gph[1]){
		if(!pth[j]){
			par[j] = 1;
			e = dfs(j);
			break;
		}
	}
	vector<int> ans;
	while(s != 1){
		ans.push_back(s);
		s = par[s];
	}
	ans.push_back(1);
	vector<int> rev;
	while(e != 1){
		rev.push_back(e);
		e = par[e];
	}
	while(!rev.empty()){
		ans.push_back(rev.back());
		rev.pop_back();
	}
	printf("%d\n", ans.size());
	for(auto &i : ans) printf("%d ", i);
}


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


int main()
{
	long long a, b, n;
	cin >> a >> b >> n;
	if (n >= b)
	{
		cout << (a*(b - 1)) / b << "\n";
	}
	else
	{
		cout<< (a*(n)) / b << "\n";
	}
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
const int MAX=1e9+7;
const int mod=1e9+7;
int a[5],s,c,flag=0;

int main()
{
	ios::sync_with_stdio(0);cin.tie(0); 
	memset(a,-1,sizeof(a));
	int n,m;
	cin>>n>>m;	
	for(int i=0;i<m;i++)
	{
		cin>>s>>c;
		if(a[s-1]==-1)
		{
			a[s-1]=c;
		}
		else if(a[s-1]!=c)
		{
			flag=1;
		}	
	}
	if(flag||a[0]==0&&n!=1)
	cout<<-1;
	else{
		
		for(int i=0;i<n;i++)
		{
			if(i==0&&a[i]==-1&&n!=1)cout<<1;
			else if(a[i]==-1)cout<<0;
			else cout<<a[i];	
		}
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  int sum = 0;
  cin >> n >> k;
  
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x; 
    if ( x < k - x ) {
      sum += x * 2;
    }
    else {
      sum += (k - x) * 2;
    }
  }
  
  cout << sum << endl;
  
}

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

int main()
{
    ll N;
    cin >> N;

    for (ll i = -200; i <= 200; i++)
    {
        for (ll j = -200; j <= 200; j++)
        {
            if (i * i * i * i * i - j * j * j * j * j == N)
            {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   vector<int> ans = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int k; cin >> k;
   cout << ans[k-1];
   return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <complex>
#include <cmath>
using namespace std;


int main(int argc, char const *argv[]) {
  int n;cin>>n;
  long long ma=0,res=0;
  for(int i = 0;i<n;++i){
    long long tmp;cin>>tmp;
    ma = max(ma,tmp);
    res += tmp;
  }
  cout<<res - ma/2<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace _20200725_M_SOLUTIONS_プロコンオープン_2020
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            a = int.Parse(Console.ReadLine()); //標準入力
            if (400 <= a && a <= 599)
            {
                Console.WriteLine(8);
            }
            else if(600 <= a && a <= 799)
            {
                Console.WriteLine(7);
            }
            else if (800 <= a && a <= 999)
            {
                Console.WriteLine(6);
            }
            else if (1000 <= a && a <= 1199)
            {
                Console.WriteLine(5);
            }
            else if (1200 <= a && a <= 1399)
            {
                Console.WriteLine(4);
            }
            else if (1400 <= a && a <= 1599)
            {
                Console.WriteLine(3);
            }
            else if (1600 <= a && a <= 1799)
            {
                Console.WriteLine(2);
            }
            else if (1800 <= a && a <= 1999)
            {
                Console.WriteLine(1);
            }
        }
    }
}


Measured memory_bytes: 27532
int printf();
int scanf();
void *malloc ();

int main ()
{
    int n;
    int *t;
    int m;
    int p;
    int x;
    int i;
    int sum;
    scanf("%d", &n);
    t = malloc(n * 4 + 9);
    i = sum = 0;
    while (i < n) {
        scanf("%d", t + i);
        sum = sum + *(t + i);
        i = i + 1;
    }
    scanf("%d", &m);
    while (m) {
        scanf("%d %d", &p, &x);
        printf("%d\n", sum - *(t + p - 1) + x);
        m = m - 1;
    }
    return 0;
}


Measured memory_bytes: 128
<?php
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU

function gets() { return trim(fgets(STDIN)); }
function geti() { return intval(gets()); }
function getVals() { return explode(' ', gets()); }
function getInts() { return array_map(intval, getVals()); }

// 解説読後 https://atcoder.jp/img/abc073/editorial.pdf

list($N, $M, $R) = getInts();
$rs = getInts();

$path = array();
for ($i = 0; $i <= $N; $i++) {
    $path[] = array_fill(0, $N+1, 300000000);
}

for ($i = 0; $i < $M; $i++) {
    list($a, $b, $c) = getInts();
    $path[$a][$b] = $c;
    $path[$b][$a] = $c;
}

// ワーシャルフロイド
for ($i = 1; $i <= $N; $i++) {
    for ($j = 1; $j <= $N; $j++) {
        for ($k = 1; $k <= $N; $k++) {
            if ($path[$j][$k] > $path[$j][$i] + $path[$i][$k]) {
                $path[$j][$k] = $path[$j][$i] + $path[$i][$k];
            }
        }
    }
}

$flag = array_fill(0, $R, false);
$ans = 300000000;

function dfs($c, $dist, $p) {
    global $flag, $ans, $path, $R, $rs;
    if ($c === $R) {
        $ans = min($ans, $dist);
        return;
    }
    for ($i = 0; $i < $R; $i++) {
        if ($flag[$i]) { continue; }
        $flag[$i] = true;
        if ($p < 0) {
            dfs($c + 1, 0, $i);
        } else {
            $f = $rs[$p];
            $t = $rs[$i];
            dfs($c + 1, $dist + $path[$f][$t], $i);
        }
        $flag[$i] = false;
    }
}

dfs(0, 0, -1);

echo $ans;


Measured memory_bytes: 9460
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    print(0, flush=True)
    s = input().strip()
    if s == 'Vacant':
        return True
    ls, rs = s, s
    l, r = 0, N
    while True:
        m = (l + r) // 2
        print(m, flush=True)
        s = input().strip()
        if s == 'Vacant':
            return True
        if (m - l) % 2 == 0 and s != ls:
            r = m
            rs = s
        elif (m - l) % 2 == 1 and s == ls:
            r = m
            rs = s
        elif (r - m) % 2 == 0 and s != rs:
            l = m
            ls = s
        elif (r - m) % 2 == 1 and s == rs:
            l = m
            ls = s

if __name__ == '__main__':
    main()

Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef long double ld;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 3;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lb lower_bound
#define ub upper_bound
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod);
#define mod_in(a) exp(a, mod-2)
#define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod)
#define deb(x) cout << #x << " " << x << endl;
#define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
ll prime[100002];
ll exp(ll a,ll b);
void sieve(ll n);
ll gcd(ll a ,ll b);
ll countdigit(ll n);
vector<ll>ft;

ll mul(ll a, ll b){
    ll ans= ((a%mod)*(b%mod))%mod;
    return ans%mod;
}
ll sub(ll a, ll b){
    ll ans = (a-b+mod)%mod;
    return ans;
}
ll add(ll a,ll b){
    ll ans = (a+b)%mod;
    return ans;
}
ll dp[2005];

ll solve(ll s){
    //cout<<dp[s];
    if(dp[s]!=-1){
        return dp[s];
    }
    if(s<3)return 0;
    ll temp=0;
    for(ll i=3;;i++) {
        //cout<<s<<" ";
        if(i==s)temp=((temp+1)%mod);
        else if(i>s)break;
        else temp=((temp+solve(s-i)) )%mod;
    }
    dp[s]=temp%mod;
    return dp[s];
    
}
int main()
{
    ll t=1;
    //ft.pb(1);
    //fact(10000001);
    //cin >> t;
    while(t--) {
        ll s;
        cin >> s;
        rep(i,0,2001)dp[i]=-1;
        cout<<solve(s);
        //cout<<dp[s];
    }
}

//
//
//
//
//
// IMPORTANT FUNCTIONS
ll exp(ll a, ll b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res%mod;
}
ll gcd(ll a,ll b){
    if(a==0)return b;
    return gcd(b%a,a);
}
void sieve(ll n) {
    for(ll i=0;i<=n;i++) {
        prime[i]=1;
    }
    prime[0]=0;prime[1]=0;
    for(ll i=2;i<=n;i++) {
        if(prime[i]==1) {
            for(ll j=2;i*j<=n;j++) {
                prime[i*j]=0;
            }
        }
    }
}
ll countdigit(ll  n)
{
    return floor(log10(n) + 1);
}


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

int main(){
    long a, b;
    char ch;
    scanf(" %ld %c %ld", &a, &ch, &b);
    if(ch=='+')
        printf("%ld\n", a+b);
    else printf("%ld\n", a-b);
    return 0;
}


Measured memory_bytes: 256
#include <cstddef>
#include <iostream>
#include <vector>

template <typename T>
class FenwickTree {
 private:
  std::vector<T> tree;

 public:
  FenwickTree(const std::size_t n) : tree(n + 1, 0) {}

  FenwickTree(const std::vector<T> &vec) : tree(vec.size() + 1) {
    for (std::size_t i = 0; i < vec.size(); i++) {
      add(i, vec[i]);
    }
  }

  std::size_t size() const { return tree.size() - 1; }

  void add(const std::size_t idx, const T x) {
    for (std::size_t i = idx + 1; i < tree.size(); i += i & (~i + 1)) {
      tree[i] += x;
    }
  }

  T query(const std::size_t idx) const {
    T res = 0;
    for (std::size_t i = idx; i != 0; i &= i - 1) {
      res += tree[i];
    }
    return res;
  }

  T query(const std::size_t l, const std::size_t r) const { return query(r) - query(l); }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, Q;
  std::cin >> N >> Q;
  FenwickTree<int64_t> ft(N);
  for (int i = 0; i < N; i++) {
    int a;
    std::cin >> a;
    ft.add(i, a);
  }
  for (int i = 0; i < Q; i++) {
    int t;
    std::cin >> t;
    switch (t) {
      case 0:
        int idx, x;
        std::cin >> idx >> x;
        ft.add(idx, x);
        break;
      case 1:
        int l, r;
        std::cin >> l >> r;
        std::cout << ft.query(l, r) << '\n';
        break;
    }
  }
  return 0;
}


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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
	
	int n ; cin>> n;
	string s ,t ;
	cin>>s>>t;
	string ans; 
	for(int i = 0 ; i< n ;++i){
		ans.pb(s[i]);
		ans.pb(t[i]);
	}
	cout<<ans;

    
    

#ifdef np
    cerr <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
 return 0; 
 }


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define INF (1<<21)//j＼左シフトして値を大きくする
#define WHITE 0
#define GLAY 1
#define BLACK 2
#define NIL -1

int n,M[MAX][MAX];//隣接行列重みつく
int prim(){
  int u,mincost;
  int d[MAX],p[MAX],color[MAX];//dは最短距離ほじM[i][j]を入れる　　別からの辺のが短ければこうしん
  int i,v;
  int sum=0;
  for(i=0;i<n;i++){
    d[i]=INF;
    p[i]=NIL;//親なし最短はinf
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    mincost=INF;
    u=NIL;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK&&d[i]<mincost){
        mincost=d[i];
        u=i;//最小距離を決定　閉路の場合は他の時み隣接していてdが保存してある最短から選ぶ
      }
    }

    if(mincost == INF)break;

    color[u]=BLACK;//uをTの頂点に追加
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INF){//uからvへ辺が追加
        if(M[u][v]<d[v]){//今までのより今回のへんのが短ければ
          d[v]=M[u][v];
          p[v]=u;//親設定
          color[v]=GLAY;
        }
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1){
      sum+=M[i][p[i]];
    }
  }
  return sum;
}

int main(){
  int i,j,weight;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&weight);
      if(weight==-1)M[i][j]=INF;
      else M[i][j]=weight;
    }
  }
  printf("%d\n",prim());
  return 0;
}



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

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

    if (n % 2 == 0)
    {
        cout << n / 2 << endl;
        return 0;
    }
    else
    {
        cout << n / 2 + 1 << endl;
        return 0;
    }
}


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

using namespace std;

int main(){
    int n;
    string s;
    string result = "";

    cin >> n;
    cin >> s;

    int st = 0;

    for(int i = 0; i < n; i++){
        result += s[i];
        if(s[i] == '('){
            st++;
        }else{
            if(st == 0){
                string tmp = result;
                result = "(";
                result += tmp;
            }else{
                st--;
            }
        }
    }

    for(; st > 0; st--){
        result += ")";
    }
    
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    ll N;
    cin >> N;
    string alphabets = "abcdefghijklmnopqrstuvwxyz";
    string ans;
    
    while (N > 26){
        ans += alphabets[(N-1)%26];
        N -= (N-1)%26;
        N /= 26;
    }
    ans += alphabets[(N-1)%26];
    reverse(all(ans));
    cout << ans << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required

// using namespace __gnu_pbds; 
using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}
// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // ordered_set <ynt> s; // order_of_key(value)

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second


const int MOD = 1e9 + 7;
int n, k, m, a, b;

long long f(long long k) {
	if(k == 0) return 1;
	return (k * f(k - 1)) % MOD;
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n >> m;
	if(n == m) {
		cout << (2LL * f(n)* f(n)) % MOD;
	} else {
		if(n == m + 1 || m == n + 1)
			cout << (f(n) * f(m)) % MOD;
		else cout << "0\n";
	} 

}	


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

using namespace std;

int
main(void){
	int n; cin >> n;
	vector<long long> vec(n);
	for(int i = 0; i < n; i++) cin >> vec[i];
	for(int i = 0; i < n; i++){
		if(vec[i] == 0){
			cout << 0;
			return 0;
		}
	}
	long long ans = 1;
	long long inf = 1e18;
	for(int i = 0; i < n; i++){
		if(ans > inf/vec[i]){
			cout << -1;
			return 0;
		}
		else ans = ans*vec[i];
	}
	cout << ans;
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, k;
string s;

int main() {
	cin >> n >> s >> k;
	k--;
	
	inc(i, n) { if(s[i] != s[k]) { s[i] = '*'; } }
	
	cout << s << endl;
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _20190622_ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            var NL = Console.ReadLine().Split(' ');
            int N = int.Parse(NL[0]);
            int L = int.Parse(NL[1]);

            int[] tastes = new int[N];

            for (int i = 0; i < N; i++)
            {
                tastes[i] = i + L;
            }
            var min = tastes.OrderBy(a => Math.Abs(a)).First();

            Console.WriteLine(tastes.Sum() - min);
        }
    }
}

Measured memory_bytes: 13396
food = []

5.times do
  food << gets.to_i
end

min = 10
sum = 0

food.each do |n|
  sum += (n/10.0).ceil * 10
  while n/10 != 0
    n %= 10
  end
  next if n == 0
  min = [min, n].min
end

puts sum - (10-min)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
ll n,x,y,q,h,j;
vector<ll> g[200005];
ll v[200005];
void dfs(ll i,ll p){
	for(ll x:g[i]){
		if(x==p) continue;
		v[x]+=v[i];
		dfs(x,i);
	}
}
int main(){
	cin>>n>>q;
	for(int i=0;i<n-1;i++) cin>>x>>y,g[x].push_back(y),g[y].push_back(x);
	while(q--){
		cin>>h>>j;
		v[h]+=j;
	}
	dfs(1,0);
	for(ll i=1;i<=n;i++) cout<<v[i]<<" ";
}


Measured memory_bytes: 25500
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, T;
  cin >> N >> T;
  map<long, long> mp;
  rep (i, N) {
    long t;
    cin >> t;
    mp[t]++;
    mp[t + T]--;
  }
  long current = 0;
  long ans = 0;
  long start = 0;
  for (auto it: mp) {
    long next = current + it.second;
    if (current == 0 and next > 0) start = it.first;
    if (current > 0 and next == 0) ans += it.first - start;
    current = next;
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>

using namespace std;
int main(void){
	
	int K;
	cin >> K;
	
	vector<int> A(K);
	for(int i=0;i<K;++i){ cin >> A[i]; }

	if( A[K-1]!=2 ){
		cout << -1 << endl;
		return 0;
	}
	
	long long min = A[K-1];
	long long max = A[K-1]*2-1;
	for(int i=K-2;i>=0;--i){
		auto min_nx = A[i] + ((min-1)/A[i])*A[i];
		if(min_nx > max){
			cout << -1 << endl;
			return 0;
		}
		min = min_nx;
		max = A[i]-1 + (max/A[i])*A[i];
	}

	cout << min << " "<< max << endl;

	return 0;
}

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

char s[10000];

int main(void){
    int i,n;
    scanf("%s",s);
    scanf("%d",&n);
    for(i=0;s[i];i++){
        if(i%n==0) printf("%c",s[i]);
    }

    return 0;
}


Measured memory_bytes: 256
use std::io;
use io_ext::Reader;

fn main() {
    let stdin = io::stdin();
    let mut r = Reader::new(stdin.lock());
    
    let mut s = r.read_line().split_whitespace();
    let (x, y): (u64, u64) = (s.next().unwrap().parse().unwrap(), s.next().unwrap().parse().unwrap());
    // let (x, y): (u64, u64) = (3, 3);
    // let (x, y) = (2, 2);
    // let (x, y) = (999999, 999999);

    println!("{}", answer(x, y));
}

fn answer(x: u64, y: u64) -> u64 {
    if (x + y) % 3 != 0 {
        return 0;
    }

    let mut pair = None;
    let sum = (x + y) / 3;
    for k in 0..(sum + 1) {
        let l = sum - k;
        let p = (k + l * 2, k * 2 + l);
        if p == (x, y) {
            pair = Some((k, l));
            break;
        }
    }

    if pair.is_none() {
        return 0;
    }

    let (k, l) = pair.unwrap();
    comb(k + l, l)
}

const R: u64 = 1000000000 + 7;

fn comb(n: u64, k: u64) -> u64 {
    let n = n % R;
    let k = if k <= n / 2 {
        k % R
    } else {
        (n - k) % R
    };

    let mut s = 1;
    for i in 0..k {
        s *= (n - i);
        s %= R;
    }
    let mut d = 1;
    for i in 1..(k + 1) {
        d *= i;
        d %= R;
    }

    for i in 0..R {
        if (i * d) % R == s {
            return i
        }
    }
    panic!()
}

/// Extension of io module.
pub mod io_ext {
    use std::io::BufRead;

    pub struct Reader<R> {
        buf: String,
        inner: R,
    }

    impl<R> Reader<R> {
        #[inline]
        pub fn new(inner: R) -> Self {
            Reader { buf: String::new(), inner: inner }
        }

        #[inline]
        pub fn into_inner(self) -> R {
            self.inner
        }
    }

    impl<R: BufRead> Reader<R> {
        #[allow(deprecated)]
        #[inline]
        pub fn read_line(&mut self) -> &str {
            self.buf.clear();
            self.inner.read_line(&mut self.buf).unwrap_or_else(|e| panic!("{}", e));
            self.buf.trim_right()
        }
    }
}

/// Module supporting to parse strings.
pub mod parse {
    use std::str::FromStr;
    use std::borrow::Borrow;

    pub trait ParseNext: Iterator {
        fn parse_next<F: FromStr>(&mut self) -> F;
    }

    impl<'a, S: Borrow<str>, I: Iterator<Item=S>> ParseNext for I {
        fn parse_next<F: FromStr>(&mut self) -> F {
            if let Some(s) = self.next() {
                match s.borrow().parse() {
                    Ok(x) => x,
                    Err(_) => panic!("provided string cannot be parsed")
                }
            } else {
                panic!("iterator has no next element")
            }
        }
    }
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args){
        Deque<String> formula = new ArrayDeque<String>();
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String input = scan.next();
            switch(input){
                case "+":
                    formula.push(String.valueOf(Double.parseDouble(formula.poll())+Double.parseDouble(formula.poll())));
                    break;
                case "-":
                    formula.push(String.valueOf(-1*Double.parseDouble(formula.poll())+Double.parseDouble(formula.poll())));                    
                    break;
                case "/":
                    formula.push(String.valueOf(1.0/Double.parseDouble(formula.poll())*Double.parseDouble(formula.poll())));
                    break;
                case "*":
                    formula.push(String.valueOf(Double.parseDouble(formula.poll())*Double.parseDouble(formula.poll())));
                    break;
                default:
                    formula.push(input);
                    break;
            }
        }
        double ans = Double.parseDouble(formula.poll());
        if(ans==(int)ans){
            System.out.println((int)ans);
        }else{
            System.out.println(ans);
        }
    }
}

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

int dx[] = {1,1,0,-1,-1,-1,0,1};
int dy[] = {0,1,1,1,0,-1,-1,-1};
string board[60];

int main(){
  
  int X, Y;
  cin >> X >> Y;
  
  for(int i=0; i<X; i++){
    cin >> board[i];
  }
  
  for(int i=0; i<X; i++){
    for(int j=0; j<Y; j++){
      if(board[i][j] == '.'){
        int count = 0;
        for(int k=0; k<8; k++){
          int x,y;
          x = i + dx[k];
          y = j + dy[k];
          if(x>=0 && x<X && y>=0  && y<Y && board[x][y] == '#'){
            count++;
          }
        }
        board[i][j] = '0' + count;
      }
    }
  }
  for(int i=0; i<X; i++){
    cout << board[i] << endl;
  }
}
  

Measured memory_bytes: 256
def countAC(s):
    counter = 0
    index = [0]
    for i in range(1,N):
        if s[i-1] == 'A':
            if s[i] == 'C':
                counter += 1
                index.append(counter)
                continue
        index.append(counter)
    return index

N,Q = (int(_) for _ in input().split())
S = input()
SIndex = countAC(S)
out = 0
for i in range(Q):
    l,r = (int(_) for _ in input().split())
    print(SIndex[r-1] - SIndex[l-1])


Measured memory_bytes: 6100
#include <stdio.h>

int linerSearch(int ,int* ,int);

int main()
{
  int count = 0;
  int a,b,c,i;
  int t[10010];

  scanf("%d",&a);
  
  for(i = 0;i < a;i++ ){
    scanf("%d",&t[i]);
  }

  scanf("%d",&b);
  
  for(i = 0; i < b; i++){
    scanf("%d",&c);
    count += linerSearch(a,t,c);
  }

  printf("%d\n",count);
  
  return 0;
}

int linerSearch(int x, int *y, int z)
{
  int i;
  
  for(i = 0; i < x; i ++){
    if(y[i] == z) return 1;
  }
  
  return 0;
}



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

def solve(N: int, K: int, A: "List[int]"):
    ix = A.index(1)

    ans = math.ceil((N-1)/(K-1))
    print(ans)


    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 14452
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
const int N=1000005;
const int MOD=998244353;
typedef long long LL;

int n,m,fac[N],inv[N];
int Ans1,Ans2;

//LL gcd(LL x,LL y) {
//	if(!y) return x;
//	return gcd(y,x%y);
//}
//
//struct Data{
//	LL x,y;
//	Data(LL _x=0,LL _y=0) {x=_x; y=_y;}
//	friend Data operator+(const Data A,const Data B){
//		Data ret; ret.y=A.y*B.y; ret.x=A.x*B.y+A.y*B.x;
//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;
//		return ret;
//	}
//	friend Data operator*(const Data A,const Data B){
//		Data ret; ret.x=A.x*B.x; ret.y=A.y*B.y;
//		LL tmp=gcd(ret.x,ret.y); ret.x/=tmp; ret.y/=tmp;
//		return ret;
//	}
//}ans;

inline int fast_pow(int x,int y){
	int ret=1;
	for(;y;y>>=1){
		if(y&1) ret=(LL)ret*x%MOD;
		x=(LL)x*x%MOD;
	}
	return ret;
}

inline int C(int x,int y){
	return (LL)fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}

int main(){
	scanf("%d%d",&n,&m);
	if(n>m) swap(n,m); fac[0]=inv[0]=1;
	for(int i=1;i<=n+m;i++) fac[i]=1ll*fac[i-1]*i%MOD;
	inv[n+m]=fast_pow(fac[n+m],MOD-2);
	for(int i=n+m-1;~i;i--) inv[i]=1ll*inv[i+1]*(i+1)%MOD;
	Ans1=1ll*2*m*C(n+m,n)%MOD; Ans2=fast_pow(C(n+m,n)*2%MOD,MOD-2);
	for(int i=1;i<=n;i++) {
		Ans1=Ans1+1ll*C(n-i+m-i,n-i)*C(i+i,i)%MOD;	
		Ans1%=MOD;
	}
	printf("%lld\n",1ll*Ans1*Ans2%MOD);
//	ans=ans+Data(1,2)*Data(C(n-i+m-i,n-i)*C(i+i,i),C(n+m,n));
//	printf("%lld\n",1ll*ans.x*fast_pow(ans.y,MOD-2)%MOD);
	return 0;	
}

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

int main(int argc, const char * argv[]) {
    int a[3];//a,b,k
    for (int i = 0; i < 3; ++i) {
        scanf("%d", &a[i]);
    }
    int A = a[0];
    int B = a[1];
    int K = a[2];
    
    for(int i = 0; i < K; i++){
        A >>= 1;
        B += A;
        i++;
        if(i >= K)break;
        B >>= 1;
        A += B;
    }

    printf("%d %d",A,B);
    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;

int A, P;

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

    std::cin >> A >> P;

    int x = 3 * A + P, y = x / 2;
    std::cout << y << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cassert>
using namespace std;
string s;
int pos;

bool CAT(){
  
  if(s[pos] == 'm'){
    pos++;
    if(s[pos] != 'e'){
      bool ok = CAT();
      if(!ok)return false;
    }
  }
  if(s[pos] == 'e'){
    pos++;
    if(s[pos] != 'w'){
      bool ok = CAT();
      if(!ok)return false;
    }
  }
  if(s[pos] == 'w'){
    pos++;
    return true;
  }

  return false;
}

int main(){
 
  while(cin >> s){
    pos = 0;
    if(/*rec(0,s.length()-1)*/ (CAT() && pos == s.length()) || s.length() == 0)cout << "Cat" << endl;
    else cout << "Rabbit" << endl;
  }
  return 0;
}

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

#define ll long long
#define vl vector<ll>
#define fo(i,a,b) for(ll i=a; i<b; i++)

int main(){
    int S, W;
    cin >> S >> W;

    if(W >= S) cout << "unsafe"  << endl;
    else cout << "safe" << endl;
       
}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

Measured memory_bytes: 3648
/*
    Ujjawal Pabreja [cuber_coder]
*/
#include <bits/stdc++.h> 
#include <functional> 
using namespace std;
#define speed_cubing    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll              long long
#define ld              long double
#define rep(i,a)        for(ll i = 0 ; i < a ; i++)
#define repe(i,a,b)     for(ll i = a ; i < b ; i++)
#define bac(i,a)        for(ll i = a ; i >= 0 ; i--)
#define bace(i,a,b)     for(ll i = a ; i >= b ; i--)
#define pb              push_back
#define in              insert
#define ff              first
#define ss              second
#define setbit(x)       __builtin_popcountll(x)
#define init(c,a)       memset(c,a,sizeof(c))
#define all(c)          c.begin(),c.end()
#define sz(c)           (ll)c.size()
#define lb              lower_bound
#define ub              upper_bound
#define maxe            *max_element
#define mine            *min_element
#define rev             reverse
#define Y				"YES"
#define N 				"NO"
#define endl            "\n"
#define debug(x)        cout << #x << " : " << x << endl;
const ll inf = 1e18;  
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 2e5 + 1;

inline ll add(ll a,ll b) {return ((a % mod) + (b % mod)) % mod;}
inline ll sub(ll a,ll b) {return ((a % mod) - (b % mod) + mod) % mod;}
inline ll mul(ll a,ll b) {return ((a % mod) * (b % mod)) % mod;}
ll pwr(ll x,ll n){
    if(n == 0){
        return 1;
    }
    if(n&1){
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    } else {
        return pwr(mul(x, x), n / 2);
    }
}
ll modInv(ll n){ 
    return pwr(n, mod - 2); 
}
ll gcd(ll a,ll b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}
// ====== Useful functions end ======
 
// ====== Global Variables begin ======

// ====== Global Variables end ======

void speed_solve(){
    ll n;
    cin >> n;
    ll ans = 1;
    set <ll> s;
    ll rem = 7 % n, d = 1;
    while (true) {
        if(!rem){
            cout << d << endl;
            return;
        }
        rem *= 10;
        rem %= n;
        rem += 7;
        rem %= n;
        if(s.count(rem)){
            cout << -1;
            return;
        } else {
            s.in(rem);
        }
        d++;
    }
    cout << -1 << endl;
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    speed_cubing;
    ll test_cases = 1;
    // cin >> test_cases;
    rep(i,test_cases){
        // cout << "Case #" << i + 1 << ": ";
        speed_solve();
    }
    return 0;
}

Measured memory_bytes: 50484
import sys
sys.setrecursionlimit(10 ** 9)
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()

def main():
    N = int(input())
    yen = [6 ** i for i in range(1, 7)]
    yen += [9 ** i for i in range(1, 6)]
    yen = [i for i in yen if i <= N]
    yen.sort(reverse=True)

    def MIN(a, b):
        if a > b:
            return b
        else:
            return a

    @lru_cache(maxsize=None)
    def dfs(x, n, m):
        n += 1
        for y in yen:
            if n >= m:
                return n
            if y > x:
                continue
            if x - y < 6:
                return n + x - y
            m = MIN(dfs(x - y, n, m), m)
        return m

    print(dfs(N, 0, N))

if __name__ == '__main__':
    main()


Measured memory_bytes: 85852
n=int(input())
a=[int(n)  for n in input().split() ]
b=[int(n)  for n in input().split() ]
c=[int(n)  for n in input().split() ]

cnt=0
ch=a[0]
for i in a:
  cnt+=b[i-1]
  if i-ch == 1:
    cnt+=c[i-2]
  ch=i
print(cnt)

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {
    
    string S;
    cin >> S;
    
    string ans;
    
    for(ll i = 2; i < S.length()-1; i+=2){
        bool f = true;
        for(ll j = 0; j < i / 2; j++){
            if(S[j] != S[j+(i/2)]) f = false;
        }
        if(f == true) ans = S.substr(0, i);
    }
    
    cout << ans.size() << endl;
    

}

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

#define INF 1001001001

template<typename T>
class BinaryIndexedTree2D {
    int H;
    int W;
    vector<vector<T> > data2d;
public:
    BinaryIndexedTree2D(int H, int W) : H(H), W(W) {
        data2d.resize(H + 1, vector<T>(W + 1, 0));
    }

    T sum(int h, int w) {
        T res = 0;
        for (int i = h; i > 0; i -= i & -i) {
            for (int j = w; j > 0; j -= j & -j) {
                res += data2d[i][j];
            }
        }
        return res;
    }

    /**
     * 左上の座標(h1, w1), 右下の座標(h2, w2) に含まれる値の累積和
     */
    T sum(int h1, int w1, int h2, int w2) {
        return sum(h2, w2) - sum(h1 - 1, w2) - sum(h2, w1 - 1) + sum(h1 - 1, w1 - 1);
    }

    void add(int h, int w, ll x) {
        for (int i = h; i <= H; i += i & -i) {
            for (int j = w; j <= W; j += j & -j) {
                data2d[i][j] += x;
            }
        }
    }
};

int main(int, char**)
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    string s; cin >> s;
    int j = 0;
    ll tmp = 0;
    while (j < s.size() && s[j] != '.') tmp = tmp*10+(s[j++]-'0');
    if (s[j] == '.') j++;
    rep(k,9) {
      if (j < s.size()) tmp = tmp*10+(s[j++]-'0');
      else tmp *= 10;
    }
    a[i] = tmp;
  }
  vector<P> prime25(n);
  rep(i,n) {
    int p2 = 0, p5 = 0;
    while (a[i]%2 == 0) { a[i] /= 2; p2++; }
    while (a[i]%5 == 0) { a[i] /= 5; p5++; }
    prime25[i] = {p2,p5};
  }
  ll ans = 0;
  const int bmax = 100;
  BinaryIndexedTree2D<int> bit(bmax,bmax);
  rep(i,n) {
    int x, y;
    tie(x,y) = prime25[i];
    x++; y++;
    ans += bit.sum(max(1,20-x),max(1,20-y),bmax,bmax);
    bit.add(x,y,1); 
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 6352
import sys
n = int(input())
xl = []
for _ in range(n):
    x, l = map(int, input().split())
    xl.append((x, l))
xl.sort(key=lambda x:x[0])
i = 0
if n==1:
    print(1)
    sys.exit(0)
while i<len(xl)-1:
    if xl[i][0]+xl[i][1] <= xl[i+1][0]-xl[i+1][1]:
        i += 1
    else:
        if xl[i][0]+xl[i][1] < xl[i+1][0]+xl[i+1][1]:
            del xl[i+1]
        else:
            del xl[i]
print(len(xl))

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  //ll n;
  //cin >> n;
  ll n;
  cin >> n;
  //string s; cin >> s;
  ll result = 0;
  bool judge = true;

  
  vector<ll> a(n),b(n+1),c(n+1);
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  ll buf = 0;
  for(i=0;i<n;i++){
    b[i+1]=b[i]+abs(buf-a[i]);
    buf=a[i];
    //cout<<b[i+1]<<endl;
  }
  
  reverse(ALL(a));
  buf=0;
  for(i=0;i<n;i++){
    c[i+1]=c[i]+abs(buf-a[i]);
    buf=a[i];
    //cout<<c[i+1]<<endl;
  }

  reverse(ALL(a));
  for(i=0;i<n;i++){
    ll l=i>0?a[i-1]:0;
    ll r=i<n-1?a[i+1]:0;
    cout<<b[i]+c[n-i-1]+abs(l-r)<<endl;
    //cout<<b[i] spa c[n-i-1] spa abs(l-r) << endl;
  }

  //cout<<result<<endl;
  





  return 0;
}

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

int main()
{
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    cout << (s < t ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256