akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    ll a, b, c, k;  cin >> a >> b >> c >> k;
    ll ans = 0;
    ans += min(k, a);
    k -= min(k,a);
    k -= min(k,b);
    if (k > 0)
        ans -= k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
#define int long long int
int32_t main()
{
     int n;
     cin>>n;
     int arr[n-1],j;
     for(j=0;j<n-1;j++)
         cin>>arr[j];
     int answer[n];
     answer[0]=arr[0];
     for(j=1;j<n-1;j++)
     {
		 answer[j]=min(arr[j],arr[j-1]);
     } 
     answer[n-1]=max(answer[n-2],arr[n-2]);
     
     int sum=0;
     for(j=0;j<n;j++)
        sum+=answer[j];
     cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

ll counting(ll n) {
  if (n == 1)
    return 1;
  return counting(n / 2) * 2 + 1;
}

int main(void) {
  ll h;
  cin >> h;
  cout << counting(h) << '\n';
  return 0;
}

Measured memory_bytes: 3628
numbers_x = []
numbers_y = []
while True:
  x,y=map(int, input().split())
  if x==0 and y==0:
    break
  if x > y:
    x,y = y,x
  numbers_x.append(x)
  numbers_y.append(y)

for i in range(len(numbers_x)):
  print(numbers_x[i],numbers_y[i])



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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k; cin>>n>>k;
    int arr[n+1];
    for (int in=1;in<=n;in++) cin>>arr[in];
    int dp[n+1];
    dp[1]=0;
    for (int i=2;i<=n;i++) {
        int currmin=dp[max(i-k,1)]+abs(arr[i]-arr[max(1,i-k)]);
        for (int j=max(1,i-k)+1;j<i;j++) {
            currmin=min(currmin, dp[j]+abs(arr[j]-arr[i]));
        }
        dp[i]=currmin;
    }
    cout<<dp[n]<<"\n";
    return 0;
}

Measured memory_bytes: 1024
X, N = list(map(int, input().split()))
P = set(list(map(int, input().split())))

if X not in P:
    print(X)
    exit(0)

for i in range(1, 200):
    if X - i not in P:
        print(X-i)
        exit(0)
    elif X + i not in P:
        print(X+i)
        exit(0)


Measured memory_bytes: 61744
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }

inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }



int main()
{
    char a[3],p=0,q=0;
    cin >>a;
    REP(i,3)
    {
        if(a[i]=='A')
            p++;
        if(a[i]=='B')
            q++;
        
    }
    if(q>0 && p>-0)
        cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sstream>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mk make_pair
#define xx first
#define yy second

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 2e5+1;



int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T=1;
//cin>>T;
while(T--){
int n;
cin>>n;
map<string,int> m;
while(n--){
    string a;
    cin>>a;
    m[a]++;
}
cout<<"AC"<<" x "<<m["AC"]<<"\n";
cout<<"WA"<<" x "<<m["WA"]<<"\n";
cout<<"TLE"<<" x "<<m["TLE"]<<"\n";
cout<<"RE"<<" x "<<m["RE"]<<"\n";
}
return 0;
}

/*_*/


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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  map<string, long long> M;

  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    M[s]++;
  }

  long long ans = 0;

  for (auto m : M) {
    ans += m.second * (m.second - 1) / 2;
  }

  cout << ans << "\n";
}

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

vector<int> dp(MAX,-1);
vector<int> g[MAX];

int dfs(int i){
    if(dp[i] != -1) return dp[i];
    int d = 0;
    rep(j,g[i].size()){
        d = max(d,dfs(g[i][j])+1);
    }
    return dp[i] = d;
}

int main(){
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
    }
    int ans = 0;
    rep(i,n) {
        if(dp[i] == -1) ans = max(ans,dfs(i));
        else ans = max(ans,dp[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8832
#include<stdio.h>
#include<stdlib.h>

#define N 100000
#define NIL -1

typedef struct Node{
  int parent, child, side;
}node;

void calc(int, int);

node A[N];
int n, depth[N];

int main(){
  int i, j, num, ch_num, root, ch, a, b;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    A[i].parent = NIL;
    A[i].child = NIL;
    A[i].side = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d", &num, &ch_num);

    for(j = 0; j < ch_num; j++){
      scanf("%d", &ch);
      
      if(j == 0)
        A[num].child = ch;

      else
        A[a].side = ch;

      a = ch;
      A[a].parent = num;
    }
  }

  for(i = 0; i < n; i++){
    if(A[i].parent == NIL)
      root = i;
  }
  
  calc(root, 0);

  for(i = 0; i < n; i++){

    printf("node %d: parent = %d, depth = %d, ", i, A[i].parent, depth[i]);

    if(A[i].parent == NIL)
      printf("root, ");

    else if(A[i].child == NIL)
      printf("leaf, ");

    else
      printf("internal node, ");

    printf("[");
    
    ch = A[i].child;
    j = 0;

    while(ch != NIL){
      if(j != 0)
        printf(", ");

      printf("%d", ch);

      ch = A[ch].side;
      j++;
    }

    printf("]\n");
  }
  
  return 0;
}

void calc(int i, int d){
  depth[i] = d;
  if(A[i].side != NIL)
    calc(A[i].side, d);
  if(A[i].child != NIL)
    calc(A[i].child, d+1);
}


Measured memory_bytes: 6372
#include<stdio.h>
int main(void){
  int A,B,C;scanf("%d%d%d",&A,&B,&C);
  if(A>=B&&A>=C){
    printf("%d\n",A*10+B+C);
  }else if(B>=A&&B>=C){
    printf("%d\n",A+B*10+C);
  }else{
    printf("%d\n",A+B+C*10);
  }
  return 0;
}


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

int main()
{
    const unsigned long long MX = 1e9, MX2 = 1e18;
    int n;cin>>n;
    unsigned long long a[n], p=1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0){
            cout<<"0\n";
            exit(0);
        }else if(a[i]==1){
            if(i!=n-1){
                cin>>a[i];
                n--;
        }}
    }
    for(int i=0;i<n;i++){
        if(p>MX && a[i]>MX){
            cout<<"-1\n";
            exit(0);
        }
        p*=a[i];
        if(p>MX2){
            cout<<"-1\n";
            exit(0);
        }
    }
    cout<< p <<'\n';
}

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

using namespace std;

vector<unsigned long long> ans;
vector<unsigned long long> v[100][10];

int main(){

    v[0][0].push_back(0);
    for(int i=1;i<=9;i++){
        v[0][i].push_back(i);
        ans.push_back(i);
    }

    unsigned long long start = 1;
    int keta = 0;
    while(ans.size()<=100000){
        start = start*10;
        for(int i=0;i<=9;i++){
            for(int j=i-1;j<=9&&j<=i+1;j++){
                if(j<0)continue;
                for(int k=0;k<v[keta][j].size();k++){
                    unsigned long long val = i*start+v[keta][j][k];
                    v[keta+1][i].push_back(val);
                    if(i!=0)ans.push_back(val);
                }
            }
        }
        keta++;
    }

        int k; cin >> k;

    cout << ans[k-1] << endl;


}

Measured memory_bytes: 3828
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    h = sorted([int(input()) for _ in range(n)])
    ans = float('inf')

    for i in range(n - k + 1):
        ans = min(ans, h[i + k - 1] - h[i])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8280
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int tb[100000];

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

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

	sort(tb, tb + n);

	int ans = 0;
	int cnt = 1;
	int prev = tb[0];
	for (int i = 1; i < n; i++) {
		int now = tb[i];
		
		if (now == prev) {
			cnt++;
		}
		else {
			if (cnt % 2 == 1) {
				ans++;
			}

			cnt = 1;
			prev = tb[i];
		}
	}

	if (cnt % 2 == 1) {
		ans++;
	}

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

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

int main(){
	int a,b;
	string s;
	cin >> a >> b >> s;
	int num[10]={};
	rep(i,10)num[i]=i;
	bool is_pos = true;
	rep(i,a+b+1){
		if(i==a){
          if(s[i]!='-')
			is_pos = false;
			continue;
		}
		bool is_num = false;
		rep(j,10){
			if(s[i]=='0'+num[j])is_num=true;
		}
		is_pos=is_pos&&is_num;
	}
	if(s.size()==a+b+1&&is_pos)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

var ans = [1e5]int{}
func main() {
  var s string
  fmt.Scan(&s)
  var n,p int
  last := 'R'
  ans := make([]int, len(s))
  for i := range s {
    if last == 'R' && s[i] == 'L' {
      ans[i-1] += (n+1)/2 
      ans[i] += n/2
      p = i
      n=0
    } else if last == 'L' && s[i] == 'R' {
      ans[p-1] += n/2
      ans[p] += (n+1)/2
      n=0
    }
    n++
    last = rune(s[i])
    
    if i == len(s)-1 && last == 'L' {
      ans[p-1] += n/2
      ans[p] += (n+1)/2
    }    
  }
  for i := 0; i < len(s); i++ {
    fmt.Printf("%d ", ans[i])
  }
}
  
  
  
  
  
  
  






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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tsii = tuple<string, int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,ans=1e9+7;
    cin>>n;
    vector<int> w(n),imos(n+1);
    imos[0]=0;
    for (int i = 0; i < n; i++)
    {
        cin>>w[i];
        imos[i+1]=imos[i]+w[i];
    }
    for (int i = 1; i < n; i++)
    {
        int tmp = abs(imos[i] - (imos[n]-imos[i]));
        ans=min(ans,tmp);
    }
    
    cout<<ans<<endl;
    return 0;
}

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

int a[105];
int selectionSort(int n,int a[])
{
	int i,j,minj,sum=0;
	for(i=0;i<n;i++)
	{
		minj=i;
		for(j=i;j<n;j++)
		{
			if(a[j]<a[minj])
			minj=j;
		}
		if(a[i]>a[minj])
		{
		
		swap(a[i],a[minj]);
		sum++;
	}
	}
	return sum;
}

int main()
{
	int n,i,ans=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ans=selectionSort(n,a);
	for(i=0;i<n;i++)
	{
		if(i!=0)
		cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<ans<<endl;
}


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

int main() {
	int h;
	while (scanf("%d", &h), h) {
		vector<int>V[5];
		rep(i, h) {
			rep(j, 5) {
				int d; scanf("%d", &d);
				V[j].push_back(d);
			}
		}
		rep(i, 5)reverse(V[i].begin(), V[i].end());
		int ans = 0;
		bool update;
		do {
			update = false;
			rep(i, h) {
				rep(j, 3) {
					int k;
					for (k = 0; j + k<5 && V[j + k].size()>i&&V[j][i] == V[j + k][i]; k++);
					if (k >= 3) {
						update = true;
						ans += V[j][i]*k;
						rep(t, k)V[j + t][i] = 0;
					}
				}
			}
			rep(i, 5) {
				rep(j, V[i].size()) {
					if (!V[i][j]) {
						V[i].erase(V[i].begin() + j);
						j--;
					}
				}
			}
		} while (update);
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int sum=0,yes=0,did=0;
    int di=a-b;
    if(a<b){
        sum=a*c;
          cout<<sum<<'\n';
    }
    else if(a>=b){
        sum+=b*c;
        yes+=di*d;
        did=sum+yes;
            cout<<did<<'\n';
    }

    return 0;
}


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

using namespace std;


#define PI			3.14159265
#define OO			1e18
#define SS       	second
#define FF       	first
#define Trace(n)  	cout<< #n <<" = "<< n << endl; 
#define ll			long long
#define endl		"\n"
#define EPS		    1e-9
//#define MOD         1e9 + 7	    
//int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
//int dy[] = { -1, 1, 0, 0, 1, -1, 1, -1 };

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


int main()
{
	//fast();
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		if ((i % 2 == 0) && (v[i] % 2))
			ans++;
	}
	cout << ans;

#ifndef ONLINE_JUDGE
	system("pause");
#endif

}

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

#define ll long long

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll l, r;
    cin >> l >> r;

    r = min(r, l + 2019);

    ll mi = 2019;
    for (ll i = l; i <= r; i++){
        for (ll j = i+1; j <=r; j++){
            mi = min(mi, (i * j)%2019);
        }
    }

    cout << mi << endl;


    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
using boost::algorithm::split;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::multiprecision::cpp_int;
using boost::multiprecision::cpp_dec_float_50;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main () {
    int N; cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double res = v[0];
    for (int i = 0; i < N; i++) {
        res = (res + v[i]) / 2.0;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]
 
 
masu = LIHW(3)
ans = "Yes"
for i in range(2):
    if masu[i+1][1]-masu[i+1][0] != masu[0][1]-masu[0][0]:
        ans = "No"
    if masu[i+1][2]-masu[i+1][1] != masu[0][2]-masu[0][1]:
        ans = "No"
for i in range(2):
    if masu[1][i+1]-masu[0][i+1] != masu[1][0]-masu[0][0]:
        ans = "No"
    if masu[2][i+1]-masu[1][i+1] != masu[2][0]-masu[1][0]:
        ans = "No"
print(ans)

Measured memory_bytes: 9228
import math
while True:
	a_2 = 0
	n = int(input())
	if n == 0:
		break
	
	score = [int(x) for x in input().split()]
	m = sum(score)/len(score)
	#print(m)

	for i in range(len(score)):
		a_2 += (score[i]-m)*(score[i]-m)/n
		#print(a_2)
	print('%.4f'% math.sqrt(a_2))

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    string s; std::cin >> s;
    int ans = 0, tmp = 0;
    rep(i, s.size()) {
        if (s[i] == 'R') tmp++;
        else chmax(ans, tmp), tmp = 0;
    }
    chmax(ans, tmp);
    std::cout << ans << "\n";
}


Measured memory_bytes: 3652
#include"iostream"
#include"string"
using namespace std;

int main()
{
	int n,k;
	k = 0;
	cin >> n;
	
	do {
		string x;
		cin >> x;
		if (x == "Y") {
			k = 1;
		};

		n=n-1;

	}while (n >= 1 && k!=1);

	if (k == 1) {
		cout << "Four";
	}
	else{
		cout << "Three";
	};
	system("pause");
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
priority_queue<pii> pq;
int n,a[200005],b[200005],ans;
void solve(){
    cin>>n;
    rep(i,0,n) cin>>a[i];
    rep(i,0,n){
        cin>>b[i];
        if(b[i]<a[i]){
            cout<<-1<<endl;
            return;
        }
        pq.push({b[i],i});
    }
    while(!pq.empty()){
        pii d=pq.top();
        pq.pop();
        int h=max(b[(d.y-1+n)%n],b[(d.y+1)%n]);
        int del=(b[(d.y-1+n)%n]+b[(d.y+1)%n]);
        int q=(d.x-h+del-1)/del;
        if(d.x-q*del<a[d.y]){
            q=(d.x-a[d.y])/del;
            if(d.x-q*del!=a[d.y]){
                cout<<-1<<endl;
                return;
            }
        }
        ans+=q;
        b[d.y]=d.x-q*del;
        if(b[d.y]!=a[d.y]) pq.push({b[d.y],d.y});
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 8816
#include<iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdlib>

using namespace std;
int main(){

  static int n;
  
  cin >> n;
  
  int x[n];
  int y[n];

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

  double sum = 0;
  for(int i=0;i<n;i++){
    sum += abs(x[i]-y[i]);
  }
  cout << setprecision(15) << sum << endl;

  sum=0;
  for(int i=0;i<n;i++){
    sum += pow(abs(x[i]-y[i]),2);
  }
  cout << setprecision(15) << sqrt(sum) << endl;

  sum=0;
  for(int i=0;i<n;i++){
    sum += pow(abs(x[i]-y[i]),3);
  }
  cout << setprecision(15) << cbrt(sum) << endl;

  int maxi =0;
  for(int i=0;i<n;i++){
    maxi =  max(maxi, abs(x[i]-y[i]) );
  }
  cout << setprecision(15) << maxi << endl;


}





Measured memory_bytes: 3504
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 100001;

int n, m;
vector <pair <int, int> > v[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for(int i = 0 ; i < m ; i++){
        int l, r, c;
        cin >> l >> r >> c;
        v[l].push_back(make_pair(i, c));
        v[r].push_back(make_pair(i, -1));
    }
    multiset <ll> s;
    set <pair <int, ll> > g;
    ll dp = 0;
    for(int i = 1 ; i <= n ; i++){
        if(i > 1){
            if(s.size() == 0) finish(-1);
            else dp = *s.begin();
        }
        for(auto &j : v[i]){
            if(j.second != -1){
                s.insert(dp + j.second);
                g.insert(make_pair(j.first, dp + j.second));
            }
            else{
                auto it = g.lower_bound(j);
                s.erase(s.find((*it).second));
                g.erase(it);
            }
        }
    }
    cout << dp << endl;
}


Measured memory_bytes: 11520
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N;
  pair<ll,ll> V[100007];
  cin >> N;
  rep(i,N){
    cin >> V[i].fr >> V[i].sc;
  }
  sort(V,V+N);
  ll K=-INF,C=0;
  rep(i,N){
    if(V[i].fr-V[i].sc>=K){
      C++;
      K=V[i].fr+V[i].sc;
    }
    K=min(K,V[i].fr+V[i].sc);
  }
  cout << C << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
    ll n,a;
    cin>>n;
    double c,b=0;
    for(ll i=0;i<n;i++){
        cin>>a;
     // cout<<a<<endl;
        b+=(double)1/a;
      //cout<<b<<endl;
    }
  //cout<<b<<endl;
    c=(double)1/b;
    printf("%.5f",c);
}

Measured memory_bytes: 256
#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>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
#define sig(x) ((x) < 0 ? -1 : 1)
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int ctz(int x) { return __builtin_ctz(x); }
int clz(int x) { return __builtin_clz(x); }

void init(string& P, vi& b){
    int i = 0, j = -1;
    b[0] = -1;
    while(i < P.size()){
        while(j >= 0 && P[i] != P[j]){
            j = b[j];
        }
        b[++i] = ++j;
    }
}

vi kmp(string& T, string& P, vi& b){
    vi ret;
    int i = 0, j = 0;
    while(i < T.size()){
        while(j >= 0 && T[i] != P[j]){
            j = b[j];
        }
        i++;
        j++;
        if(j == P.size()){
            ret.push_back(i - j);
            j = b[j];
        }
    }
    return ret;
}

const int maxn = 5e6 + 5;
vi g[maxn];
int vis[maxn], has[maxn];
vi topo;
bool ok = 0;

void dfs(int u){
    vis[u] = 1;
    for(int v : g[u]){
        if(vis[v] == 1){
            ok = 1;
        }
        if(!vis[v]){
            dfs(v);
        }
    }
    vis[u] = 2;
    if(has[u]) 
        topo.push_back(u);
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  string s, t;
  cin >> s >> t;
  while(s.size() < t.size()){
      s += s;
  }
  vi b(2 * s.size() + 1);
  init(t, b);
  string tmp = s + s;
  vi occ = kmp(tmp, t, b);
  reverse(all(occ));
  for(int x : occ){
      if(x >= s.size()) continue;
      has[x] = 1;
      g[x].push_back((x + t.size()) % s.size());
  }
  for(int x : occ){
      if(!vis[x]){
          dfs(x);
      }
  }
  if(ok){
      cout << -1;
      return 0;
  }
  reverse(all(topo));
  vi dp(maxn);
  for(int u : topo){
      for(int v : g[u]){
          dp[v] = max(dp[v], dp[u] + 1);
      }
  }
  int res = 0;
  for(int i = 0; i < s.size(); i++){
      res = max(res, dp[i]);
  }
  cout << res;
}


Measured memory_bytes: 211364
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n);
  Cin(string, s);

  map<char, int> mp;
  for (auto e : s) mp[e]++;

  cout << (mp['R'] > mp['B'] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int D = sc.nextInt();
        int A[][] = new int[H][W];
        int rA[][] = new int[H*W+1][2];
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                int x = sc.nextInt();
                A[i][j] = x;
                rA[x][0] = i;
                rA[x][1] = j;
            }
        }
        
        long cost[] = new long[H*W+1];
        for(int a = 1; a <= H*W; a++ ){
            if( a + D > H*W ) break;
            int i = rA[a][0];
            int j = rA[a][1];
            int x = rA[a+D][0];
            int y = rA[a+D][1];
            cost[a+D] = cost[a] + (long)Math.abs(i - x) + (long)Math.abs(j - y);
        }
        
        int Q = sc.nextInt();
        for(int i = 0; i < Q; i++) {
            int L = sc.nextInt();
            int R = sc.nextInt();
            System.out.println( cost[R] - cost[L] );
        }
    }
}


Measured memory_bytes: 63680
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	cout << (1 << b)*(b * 1900 + (a - b) * 100) << endl;
	return 0;
}


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

static int_fast32_t fastabs(int_fast32_t v)
{
    return (v < 0) ? -v : v;
}

int main(void)
{
    size_t n, m;
    scanf("%zu %zu", &n, &m);
    int_fast32_t x[51][2];
    for (size_t i = 0; i < n; ++i) {
        scanf("%" SCNdFAST32 " %" SCNdFAST32, &x[i][0], &x[i][1]);
    }
    int_fast32_t y[51][2];
    for (size_t j = 0; j < m; ++j) {
        scanf("%" SCNdFAST32 " %" SCNdFAST32, &y[j][0], &y[j][1]);
    }
    for (size_t i = 0; i < n; ++i) {
        size_t index = 0;
        int_fast32_t minvalue = INT_FAST32_MAX;
        for (size_t j = 0; j < m; ++j) {
            int_fast32_t value = fastabs(x[i][0] - y[j][0]) + fastabs(x[i][1] - y[j][1]);
            if (value < minvalue) {
                minvalue = value;
                index = j + 1;
            }
        }
        printf("%zu\n", index);
    }
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int a, b, c; cin >> a >> b >> c;
  cout << (c % __gcd(a, b) == 0 ? "YES\n" : "NO\n");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>

typedef long long ll;

#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

ll N,K,cnt,ans;
vector<ll> A(200100),mf(200100,-1),ms(200100,-1);
bool once = false;

void dfs(ll now, ll cnt){
  ans = now;
  if(cnt == K) return;
  
  if(mf[now] != -1 && ms[now] == -1 && !once){
    ms[now] = cnt;
    ll d = (K - mf[now]) / (ms[now] - mf[now]);
    cnt = mf[now] + d * (ms[now] - mf[now]);
    once = true;
    dfs(now, cnt);
    return;   
  }
  else
    mf[now] = cnt;
  
  dfs(A[now],cnt+1);
}

int main(){
  cin >> N >> K;
  rep(i,N) cin >> A[i+1];
  dfs(1,0);
  cout << ans << endl;
}
      


Measured memory_bytes: 7900
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
string s;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	cout<<s.substr(0,3)<<endl;
	return 0;
}


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

signed main(){
	int n,x,a[200010] = {},ind = 1;
	bool used[200010] = {};
	cin >> n >> x;
	if(x == 1 || x == n * 2 - 1){
		printf("No\n");
		return 0;
	}
	if(n == 2){
		printf("Yes\n1\n2\n3\n");
		return 0;
	}
	if(x == 2){
		a[n] = 2;
		a[n - 1] = 1;
		a[n - 2] = 3;
		a[n + 1] = 4;
		for(int i = 0;i < n * 2 - 1;i++){
			if(!a[i]){
				a[i] = ind + 4;
				ind++;
			}
		}
	}else{
		a[n] = x;
		a[n - 1] = x + 1;
		a[n - 2] = x - 1;
		a[n + 1] = x - 2;
		for(int i = x - 2;i <= x + 1;i++) used[i] = true;
		for(int i = 0;i < n * 2 - 1;i++){
			if(!a[i]){
				while(used[ind]) ind++;
				a[i] = ind;
				used[ind] = true;
			}
		}
	}
	printf("Yes\n");
	for(int i = 0;i < n * 2 - 1;i++) printf("%d\n",a[i]);
	return 0;
}

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


int main() {
    long long int N;
    std::cin >> N;

    std::map<int, int> prime_counts;
    long long int max = sqrt(N);
    for (int i = 2; i <= max; i++) {
        while (N % i == 0) {
            if (prime_counts.find(i) == prime_counts.end()) {
                prime_counts[i] = 0;
            }
            prime_counts[i]++;
            N /= i;
        }
        max = sqrt(N);
    }


    int count = 0;
    for (auto && pair: prime_counts) {
        int pc = pair.second;
        for (int i = 2;; i++) {
            count++;
            pc -= i;
            if (pc <= 0) {
                break;
            }
        }
    }
    if (N != 1) {
        count++;
    }

    std::cout << count << std::endl;
}


Measured memory_bytes: 3728
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextInt();
        long b=sc.nextInt();
        System.out.println(a*b/gcd(a,b));

    }

    static long gcd(long m, long n) {
        if(m<n){
            n=m+n;
            m=n-m;
            n=n-m;
        }
        m%=n;
        if(m==0){
            return n;
        }else{
            return gcd(n,m);
        }

    }

}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
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; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    ll ans = 0;
    rep(i,N) cin >> A[i];
    rep(i,N) B[i] = A[i] - i;
    map<ll, int> mp;
    rep(i,N) mp[B[i]]++;
    rep(i,N) ans += mp[-A[i]-i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 27472
#include<iostream>
using namespace std;
void fswap(int *x, int *y) {
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
}
int main() {
	int n, a[100], cnt = 0;
	cin >> n;
	for (int i = 0; i<n; ++i) cin >> a[i];
	for (int i = 0; i<n - 1; ++i) {
		int minj = i;
		for (int j = i + 1; j<n; ++j) {
			if (a[j]<a[minj])
				minj = j;
		}
		fswap(&a[i], &a[minj]);
		if (i != minj) ++cnt;
	}
	for (int i = 0; i<n; ++i) {
		if (i) cout << " ";
		cout << a[i];
	}
	cout << endl << cnt << endl;
	return 0;
}


Measured memory_bytes: 3104
def main():

    # 2 <= n <= 200
    # -100 <= l <= 100

    n, l = map( int, input().split())

    moto = 0

    min = l + 1 - 1
    min = abs(min)
    default_i = 1

    for i in range(n):
        i += 1
        aji = l + i -1
        abs_aji = abs(aji)
        if(abs_aji < min):
            min = abs_aji
            default_i = i

        moto += aji
    
    tabeta = moto - (l + default_i - 1)
    
    print(tabeta)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;
// B
int main(){
    int n; cin >> n;
    ll ans =1;
    for (ll i = 1; i <= n ; ++i) {
        ans = (ans*i) % 1000000007;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 1 << 16
#define MAX_V 10
using namespace std;
int d[MAX_V+1][MAX_V+1];
int maxv;

void warshall_floyd() {
	for (int k = 0; k <= maxv; ++k) {
		for (int i = 0; i <= maxv; ++i) {
			for (int j = 0; j <= maxv; ++j) {
				d[i][j] = (d[i][k] + d[k][j] < d[i][j]) ? d[i][k] + d[k][j] : d[i][j];
			}
		}
	}
	return;
}

int main() {
	int m, a, b, c, minv, minsum;

	while (cin >> m, m) {
		for (int i = 0; i < MAX_V; ++i) {
			for (int j = 0; j < MAX_V; ++j) {
				d[i][j] = (i == j) ? 0 : INF;
			}
		}

		maxv = 0;
		while (m--) {
			cin >> a >> b >> c;
			maxv = (b > maxv) ? a : maxv;
			maxv = (b > maxv) ? b : maxv;
			d[a][b] = c;
			d[b][a] = c;
		}
		warshall_floyd();

		int sum[MAX_V] = { 0 };
		for (int i = 0; i <= maxv; ++i) {
			for (int j = 0; j <= maxv; ++j) {
				sum[i] += d[i][j];
			}
		}

		minsum = INF;
		for (int i = 0; i <= maxv; ++i) {
			if (sum[i] < minsum) {
				minv = i;
				minsum = sum[i];
			}
		}
		cout << minv << " " << minsum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}
void Show(array<char,26> Ns) {
	for (int i = 0; i < 26; i++) {
		cout <<'a' +i  << "->" << Ns[i]  << endl;
	}
}


int main() {
	int X, A, B;
	cin >> X >> A >> B;
	cout << (X - A) % B << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
using namespace std;
#define rep(p,q) for(int i = p;i < q; i++)
#define big (long long int)(10e9 + 7)

int siki(string &str, int &i);
int kou(string &str, int &i);
int insu(string &str, int &i);
int number(string &str, int &i);

int main(void) {
	int num = 0;
	cin >> num;
	rep(0, num) {
		string str;
		int x = 0;
		cin >> str;
		cout << siki(str, x) << endl;
	}
}

int siki(string &str,int &i) {
	int val1 = kou(str,i);
	while (str[i] == '+' || str[i] == '-') {
		char op = str[i];
		i++;
		int val2 = kou(str, i);
		if (op == '+') {
			val1 = val1 + val2;
		}
		else
		{
			val1 = val1 - val2;
		}
	}
	return val1;
}

int kou(string &str, int &i) {
	int val1 = insu(str, i);
	while (str[i] == '*' || str[i] == '/') {
		char op = str[i];
		i++;
		int val2 = insu(str, i);
		if (op == '*') {
			val1 = val1 * val2;
		}
		else {
			val1 = val1 / val2;
		}
	}
	return val1;
}

int insu(string &str, int &i) {
	int val1 = 0;
	if(str[i] != '(')val1 = number(str, i);
	else if(str[i] == '(') {
		i++;
		val1 += siki(str, i);
		i += 1;
	}
	return val1;
}

int number(string &str, int &i) {
	int val1 = 0;
	int val2 = 0;
	if (str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' || str[i] == '4' || str[i] == '5' || str[i] == '6' || str[i] == '7' || str[i] == '8' || str[i] == '9') {
			 val1 = (int)str[i] - (int)'0';
		i++;
		if ( str[i] == '0' || str[i] == '1' || str[i] == '2' || str[i] == '3' || str[i] == '4' || str[i] == '5' || str[i] == '6' || str[i] == '7' || str[i] == '8' || str[i] == '9') {
			int now = i;
			val2 += number(str, i);
			val1 = val1 * pow(10,i - now);
			val1 += val2;

		}
	}
	return val1;
}

Measured memory_bytes: 3268
from sys import stdin
input = stdin.readline


def main():
  from math import gcd
  K = int(input())

  sum_ = 0
  for a in range(1, K+1):
    for b in range(1, K+1):
      for c in range(1, K+1):
        sum_ += gcd(gcd(a, b), c)

  print(sum_)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 68960
a1=list(map(int, input().split()))
a2=list(map(int, input().split()))
a3=list(map(int, input().split()))
n=int(input())
a=[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
for i in range(n):
  b = int(input())
  if b in a1:
    a[0][a1.index(b)] = 1
  elif b in a2:
    a[1][a2.index(b)] = 1
  elif b in a3:
    a[2][a3.index(b)] = 1
ans = 'No'
if a[0] == [1, 1, 1]:
  ans = 'Yes'
elif a[1] == [1, 1, 1]:
  ans = 'Yes'
elif a[2] == [1, 1, 1]:
  ans = 'Yes'
elif a[0][0]==1 and a[1][0]==1 and a[2][0]==1:
  ans = 'Yes'
elif a[0][1]==1 and a[1][1]==1 and a[2][1]==1:
  ans = 'Yes'
elif a[0][2]==1 and a[1][2]==1 and a[2][2]==1:
  ans = 'Yes'
elif a[0][0]==1 and a[1][1]==1 and a[2][2]==1:
  ans = 'Yes'
elif a[0][2]==1 and a[1][1]==1 and a[2][0]==1:
  ans = 'Yes'
print(ans)

Measured memory_bytes: 3188
import java.io.PrintWriter
import java.util.*
import java.math.*
import java.lang.*

val pw = PrintWriter(System.out)
val MOD: Long = (1e+9 + 7).toLong()


fun main(args: Array<String>) {
    var i = 1
    var s = readLong() 
    val cands = mutableListOf<Long>()
    while(!cands.contains(s)) {
        i++
        cands.add(s)
        s = if(s % 2L == 0L) s / 2L else 3L * s + 1L
    }
    println(i)
    pw.flush()
}

/****** Declared Functions and Data Structures ******/
// IO
fun read() = readLine()!!
fun readInt() = read().toInt()
fun readLong() = read().toLong()
fun readDouble() = read().toDouble()
fun readListOfString() = read().split(" ")
fun readListOfInt() = readListOfString().map { it.toInt() }
fun readListOfLong() = readListOfString().map { it.toLong() }
fun readListOfDouble() = readListOfString().map { it.toDouble() }

fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun Float.format(digits: Int) = String.format("%.${digits}f", this)

fun print(value: Any) { pw.print(value) }
fun println(value : Any) { pw.println(value) }

fun<T> permutations(src: List<T>): List<List<T>> {
    if(src.size == 1) return listOf(src)
    val perms = mutableListOf<List<T>>()
    val insertElement = src[0]
    permutations(src.drop(1)).forEach { perm ->
        for(i in 0..perm.size) {
            val newPerm = perm.toMutableList()
            newPerm.add(i, insertElement)
            perms.add(newPerm.toList())
        }
    }
    return perms
}

// return nCr, if you want nCr, please access v[n][r]
fun combinations(n: Long): List<List<Long>> {
    val v = (0..n).map { (0..n).map{0L}.toMutableList() }.toMutableList()
    for(i in 0 until v.size) {
        v[i][0] = 1L
        v[i][i] = 1L
    }
    for(i in 0 until v.size) {
        for(j in 1 until i) {
            v[i][j] = (v[i-1][j-1] + v[i-1][j]) % MOD
        }
    }
    return v.map { it.toList() }.toList()
}

// should be a >= b
fun gcd(a: Long, b: Long): Long = 
    if(b == 0L) a else gcd(b, a % b)

// shoud be a >= b
fun lcm(a: Long, b: Long): Long = 
    a / gcd(a, b) * b

fun sumDigits(num_: Long): Long {
    var num = num_
    var rtn: Long = 0
    while(num != 0.toLong()) {
        val tmp = num % 10
        rtn += tmp
        num /= 10
    }
    return rtn
}

fun isDecimal(v: Double): Boolean = ((v - Math.floor(v)) != 0.0)

// Data Structures
class Stack<T>(private var st: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = st.isEmpty()
    fun top(): T = st.last()
    fun push(e: T) { st.add(e) }
    fun pop() { st = st.dropLast(1).toMutableList() }
}

class Queue<T>(private var que: MutableList<T> = mutableListOf<T>()) {
    fun isEmpty() = que.isEmpty()
    fun top(): T = que.first()
    fun push(e: T) { que.add(e) }
    fun pop() { que = que.drop(1).toMutableList() }
}


Measured memory_bytes: 31852
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const int MAXN = 55;

int n;
int c[MAXN];
int p[MAXN];
int sz[MAXN];
int cnt[MAXN];

ll ans,X,D;
ll f[MAXN * MAXN * MAXN];
ll sum[MAXN];
ll el[MAXN];

vector<int> e[MAXN];
vector<pair<int,ll> > item;

bool cmp(const int &a,const int &b)
{
	return sz[a] * sum[b] > sz[b] * sum[a];
}

void dfs(int u)
{
	sum[u] = c[u];
	sz[u] = 1;
	for (int i = 0;i < e[u].size();i++)
	{
		dfs(e[u][i]);
		sum[u] += sum[e[u][i]];
		sz[u] += sz[e[u][i]];
	}
}

int main()
{
	scanf("%d%lld%lld%d",&n,&X,&D,&c[1]);
	for (int fa,i = 2;i <= n;i++)
	{
		scanf("%d%d",&c[i],&fa);
		e[fa].push_back(i);
	}
	dfs(1);
	for (int i = 1;i <= n;i++)
	{
		cnt[i] = (i == 1 ? 50 : min(50ll,D));
		el[i] = (i == 1 ? 1e18 : D - cnt[i]);
		for (int j = 0;(1 << j) <= cnt[i];j++)
		{
			item.push_back(make_pair(sz[i] * (1 << j),sum[i] * (1 << j)));
			cnt[i] -= 1 << j;
		}
		if (cnt[i])
			item.push_back(make_pair(sz[i] * cnt[i],sum[i] * cnt[i]));
	}
	for (int i = 1;i <= n;i++)
		p[i] = i;
	sort(p + 1,p + n + 1,cmp);
	for (int i = 1;i <= 50 * n * n;i++)
		f[i] = 1e18;
	for (int i = 0;i < item.size();i++)
		for (int j = 50 * n * n - item[i].first;j >= 0;j--)
			f[j + item[i].first] = min(f[j + item[i].first],f[j] + item[i].second);
	int st = 0;
	for (int i = 50 * n * n;i >= 0;i--)
		if (X >= f[i])
		{
			X -= f[i];
			st = i;
			break;
		}
	int cur = 1,at = 1;
	ll tot = 0;
	while (at <= n && cur > el[p[at]])
	{
		at++;
		cur = 1;
	}
	for (int i = st;i >= 0;i--)
	{
		while (at <= n && X >= sum[p[at]])
		{
			ll t = min(el[p[at]] - cur + 1,X / sum[p[at]]);
			cur += t;
			X -= t * sum[p[at]];
			tot += t * sz[p[at]];
			while (at <= n && cur > el[p[at]])
			{
				at++;
				cur = 1;
			}
		}
		ans = max(ans,i + tot);
		X += f[i] - (i ? f[i - 1] : 0);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1280