akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  if (a == b && a != c) printf("Yes");
  else if (b == c && b != a) printf("Yes");
  else if (a == c && b != a) printf("Yes");
  else printf("No");
  return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

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

const long long INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s; cin>>s;
  
  int rep = 0;
  int res = 0;
  
  rep(i,s.length()) {
    
    if (s[i] == 'R') {
      ++rep;
    } else {
      rep = 0;
    }
    
    res = max(res, rep);
  }

  cout<<res;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector> 
using namespace std;
int main(void){
    
    int N;
    cin >> N;
    vector<int> A(N);
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for(int i = 0; i < N; i++){
        if(A[i] % 2 != 0){
            cout << 0 << endl;
            return 0;
        }
    }
    
    int ans = 0;
    bool check = true;
    
    while(true){
        for(int i = 0; i < N; i++){
            
            if(A[i] % 2 != 0){
                check = false;
                
            }
            else{
                A[i] /= 2;
            }
        }
        
        if(check) ans++;
        else break;
    }

    cout << ans << endl;
    
}


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

int main(){
	int N; cin>>N;
	vector<int> A(N); rep(i, N) cin>>A[i];
	sort(A.begin(), A.end());
	int n = A[N-1], r = 0;
	int mindiff = INT_MAX;
	rep(i, N-1){
		int diff = abs(n - 2*A[i]);// |n - 2*ai|
		if(mindiff > diff){ mindiff = diff; r = A[i]; }
	}
	cout<< n <<" "<< r <<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

int main(void){
    FAST_IO

    ll n,k;
    cin >> n >> k;
    vll v(100000+1);

    rep(i,n){
        ll a,b;
        cin >> a >> b;
        v[a] += b;
    }

    rep(i,100000+1){
        k -= v[i];
        if(k <= 0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

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

  int n;
  cin >> n;

  int iti = n % 10;

  if (iti == 2 || iti == 4 || iti == 5 || iti == 7 || iti == 9) {
    cout << "hon" << endl;
  } else if (iti == 0 || iti == 1 || iti == 6 || iti == 8)
    cout << "pon" << endl;
  else {
    cout << "bon" << endl;
  }

  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    long long x, y;
    cin >> x >> y;

    long long ans = 1, tmp = x, t = 1;
    for (long long i = 1; tmp * 2 <= y; i *= 2) {
        tmp *= 2;
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*
author:Manson
date:7.7.2018
theme:
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1005;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b,c;
	cin>>a>>b>>c;
	if(a < b){
		swap(a,b);
	}
	if(a < c){
		swap(a,c);
	}
	if(b < c){
		swap(b,c);
	}
	cout<<(10*a+b+c)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

string s;
string t;
bool existS[26];
bool existT[26];
vector<int> poss[26];

signed main() {
	int i;
	
	cin >> s >> t;
	rep(i, s.length()) existS[s[i] - 'a'] = true;
	rep(i, t.length()) existT[t[i] - 'a'] = true;
	rep(i, 26) {
		if (existT[i] && !existS[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	
	rep(i, s.length()) poss[s[i] - 'a'].push_back(i);
	rep(i, s.length()) poss[s[i] - 'a'].push_back(s.length() + i);
	
	int pos = -1;
	int ans = 0;
	rep(i, t.length()) {
		int id = t[i] - 'a';
		int iter = upper_bound(poss[id].begin(), poss[id].end(), pos) - poss[id].begin();
		ans += poss[id][iter] - pos;
		pos = poss[id][iter] % s.length();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3768
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sn = new Scanner(System.in);
        
        int n = sn.nextInt();
        List<String> s = new ArrayList<>();
        int cnt = 0;
		Set<String> checkHash = new HashSet<String>();
        
        while (sn.hasNext()) {
            s.add(sn.nextLine());
        }
        
        for(String str : s) {
            if(checkHash.contains(str)) {
				// 重複があればtrueをセットし終了
				cnt++;
			} else {
				// 重複しなければハッシュセットへ追加
				checkHash.add(str);
			}
        }
        System.out.print(n - cnt);
    }
}


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

int main() {
  int64_t a,b,c,k;
  cin>>a>>b>>c>>k;

  if(k<a) cout<<k<<endl;
  else if(k<=a+b) cout<<a<<endl;
  else cout<<2*a+b-k<<endl;

  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(sz(s) <= n)
		cout << s << endl;
	else {
		s.erase(n,sz(s));
		s += "...";
		cout << s << endl;
	}
	return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s,t;
    string u="";
    cin>>s>>t;
    for(int i=0;i<n;i++){
        u+=s[i];
        u+=t[i];
    }
    cout<<u<<endl;
    return 0;
}

Measured memory_bytes: 256
def getDigits(n):
  digits = []
  while n > 0:
    digits.append(n % 10)
    n //= 10
  return digits

def firstValidNumber(n, digits):
  while True:
    isValid = True
    currentDigits = getDigits(n)
    for digit in currentDigits:
      if digit in digits:
        isValid = False
        break
    if isValid:
      return n
    n += 1
  return n

n, k = map(int, input().split())
digits = list(map(int, input().split()))
print(firstValidNumber(n, digits))

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] n = new int[3];
    for (int i = 0; i < 3; i++) {
      n[i] = sc.nextInt();
    }
    Arrays.sort(n);
    for (int i = 0; i < 3; i++) {
      System.out.print(n[i]);
      if (i != 2) {
        System.out.print(" ");
      }
    }
    System.out.println();
  }
}


Measured memory_bytes: 26184
list = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}
str = input()
ans = 'Yes'
for alpha in list:
  cnt = str.count(alpha)
  if cnt % 2 == 1:
    ans = 'No'
    break
    
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

#include<cstdio>

#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORq(i, m, n) for(int i = (m); i < (n); i++)
#define FORr(i, n) for (int i = (n); i >= 0; i++)


int main() {
	string S;
	cin >> S;

	int answer = 0;
	if (S.size() == 1) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = 1; i < S.size(); i++) {
		if (S[i] == S[i - 1]) {
			answer++;
			if (S[i] == '0') {
				S[i] = '1';
			}
			else {
				S[i] = '0';
			}
		}
	}

	cout << answer << endl;
}

Measured memory_bytes: 512
using System;
using System.Linq;
public class Hello{
    public static void Main(){
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var dp = new int[n + 1];
        for(var i = 1;i < n + 1;i++){
            dp[i] = 10000;
        }
        dp[0] = 0;
        dp[1] = Math.Abs(a[1] - a[0]);
        for(var i = 2;i < n;i++){
            dp[i] = Math.Min(dp[i - 2] + Math.Abs(a[i] - a[i - 2]),dp[i - 1] + Math.Abs(a[i] - a[i - 1]));
        }
        
        Console.WriteLine(dp[n - 1]);
    }
}


Measured memory_bytes: 18144
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<string.h>
#include<math.h>
using namespace std;
#define N 100000
#define MP make_pair
typedef pair<int, int> P;
int n;
int a[N], cnt[3];
int main() 
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (a[i] % 2)
		{
			cnt[0]++;
		}
		if (!(a[i] % 2))
		{
			cnt[1]++;
		}
		if (!(a[i] % 4))
		{
			cnt[2]++;
		}
	}
	if(cnt[0] > cnt[2] && !(n % 2))
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
/*-------enazuma11----------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define F first
#define S second
#define M 1000000007
 

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
	    string s;
	    cin>>s;
	    ll n=s.size();
	    ll i=0;
	    ll c=0;
	    ll ans[n]={};
	    for(i=0;i<n;){
	    	c=0;ll rr=0,r=0,l=0,lr=0;
	    	while(i<n && s[i]!='L'){
	    		i++;
	    		r++;
	    	}
	    	//cout<<i<<" ";
	    	lr=i;
	    	rr=i-1;
	    	while(i<n && s[i]!='R'){
	    		i++;
	    		l++;
	    	}
	         ll ch=max(r,l)-1;
	         c=l+r;
	         if(c%2==0){
	         ans[rr]=c/2;
	         ans[lr]=c/2;
	         }else{
	         	if(l>r){
	         		ans[lr]=c/2+1;
	         		ans[rr]=c/2;
	         	}else{
	         		ans[rr]=c/2+1;
	         		ans[lr]=c/2;
	         	}
	         	if(ch%2==1){
	         	swap(ans[rr],ans[lr]);	
	         	}
	         }
	    }
	    for(auto i:ans)
	    cout<<i<<" ";
	}
	return 0;
}


Measured memory_bytes: 1488
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;
#define ll long long
const int MAXN = 2e5 +5;
int a[MAXN],b[MAXN];
char s[MAXN];
int main()
{
    int n,m;
    set<pair<int,int> > que;
    vector<int> ans;
    scanf("%d%d",&n,&m);
    scanf("%s",s);
    que.insert(make_pair(0,0));
    for(int i = 1;i<=n;i++) 
    {
        if(s[i] == '0') {
            bool can = false;
            // cout<<i<<endl;
            while (!que.empty())
            {
                int start_point = (*que.begin()).second;
                int times = (*que.begin()).first;
                // cout<<times<<' '<<start_point<<endl;
                if(i - start_point <= m) {
                    can = true;
                    que.insert(make_pair(times+1,i));
                    b[i] = start_point;
                    // cout<<"ch"<<endl;
                    break;
                }
                else que.erase(que.begin());
            }   
            if(!can) return printf("-1\n"),0;
        }
    }
    for(int i = n;i != 0;i = b[i])
    {
        // printf("%d->%d\n",i,b[i]);
        ans.push_back(i - b[i]);
    }
    for(int i = (int)ans.size()-1;i >= 0;i--)
    {
        printf("%d",ans[i]);
        if(i != 0) printf(" ");
    }
    printf("\n");
    return 0;
}

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

#define ll long long int
#define li int64_t

int main()
{
	string s;
	cin>>s;
	if(s[s.length()-1] == 's')
	{
		s.push_back('e');
		s.push_back('s');;
	}	
	else
	{
		s.push_back('s');
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    if ( a == b && b == c ) ans = 1;
    else if ( a == b || b == c || c == a ) ans = 2;
    else                                   ans = 3;
    cout << ans << endl; 
    return 0;
}


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

public class Test
{
	public static void Main()
	{
		// my code goes here
		
		string s = Console.ReadLine();
		int n = s.Length;
		int counter = 0;
		for(int i=0;i!=n/2;i++){
			if(s.Substring(i,1)!=s.Substring(n-1-i,1)){
				counter++;
			}
		}
		Console.WriteLine(counter);
		
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <stdio.h>
#include<string>
#include<cctype>

int main()
{
    std::string w,t,thoge;
    int count = 0;

    std::cin>>w;

    while(1)
    {
        t="";
        std::cin>>thoge;
        if(thoge=="END_OF_TEXT")
        {
            std::cout<<count<<std::endl;
            break;
        }

        for(int i = 0; i < thoge.size();i++)
        {
            t += tolower(thoge[i]);
        }

        if(w==t)
        {
            count++;
        }


    }


}




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

int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  int ans=0;
  if(n>=k){
    ans=k*x;
    ans=ans+(n-k)*y;
  }else{
    ans=n*x;
  }

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    double weight;
    while(scanf("%lf",&weight) != EOF) {
        if(weight <= 48.00) {
            puts("light fly");
        } else if(weight <= 51.00) {
            puts("fly");
        } else if(weight <= 54.00) {
            puts("bantam");
        } else if(weight <= 57.00) {
            puts("feather");
        } else if(weight <= 60.00) {
            puts("light");
        } else if(weight <= 64.00) {
            puts("light welter");
        } else if(weight <= 69.00) {
            puts("welter");
        } else if(weight <= 75.00) {
            puts("light middle");
        } else if(weight <= 81.00) {
            puts("middle");
        } else if(weight <= 91.00) {
            puts("light heavy");
        } else {
            puts("heavy");
        }
    }
    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
long long n, a[200005], b[200005], c[200005], d[200005];
int main(){
       cin>>n;
       for(long long i=1; i<=n; i++){
              cin>>a[i]>>b[i];
              c[i]=a[i]+b[i];
              d[i]=(a[i]-b[i]);
       }
       sort(c+1, c+n+1);
       sort(d+1, d+n+1);
       cout<<max(c[n]-c[1], d[n]-d[1]);
       return 0;
}

Measured memory_bytes: 9872
import re


def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + lt:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)


s = input().strip()
t = input().strip()

print(solve(s, t))

Measured memory_bytes: 3188
def dfs(num):  # 深さ優先探索
    used.append(num)
    for t in adj[num]:
        if t not in used:
            dfs(t)


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

adj = [[] for i in range(n)]  # G[i]は、頂点iと隣接する頂点
edges = []

for i in range(m):
    a, b = [int(i) - 1 for i in input().split()]
    adj[a].append(b)
    adj[b].append(a)
    edges.append([a, b])

ans = 0
for a, b in edges:
    # a-b感の辺を取り除く
    adj[a].remove(b)
    adj[b].remove(a)

    used = []
    dfs(0)  # 頂点1から（どこからでもいい）、接続している点を埋め尽くす
    if len(used) != n:
        ans += 1
    adj[a].append(b)
    adj[b].append(a)

print(ans)


Measured memory_bytes: 3064
a,b,c=map(int,input().split())
d=c
i=1
ct=0
while True:
    c=d*i
    
    if(c>=a and c<=b):
        ct=ct+1
        
    i=i+1
    if(c>=a and c>b):
        break
print(ct)
    
          


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

using namespace std;

#define FaSt ios::sync_with_stdio(0),cin.tie(0);
#define random uniform_int_distribution<long long>(1, 2000000000000000LL)(rng)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * ((uint64_t) new char | 1));

const int N = 100005;
int n, a[N], dp[N];
bool solved[N];

int calc(int i)
{
    if (solved[i])
    {
        return dp[i];
    }
    
    if (i == n - 1)
    {
        return 0;
    }
    
    if (i < n - 2)
    {
        dp[i] = min(abs(a[i + 1] - a[i]) + calc(i + 1), abs(a[i + 2] - a[i]) + calc(i + 2));
    }
    else
    {
        dp[i] = abs(a[i + 1] - a[i]) + calc(i + 1);
    }
    
    solved[i] = 1;
    return dp[i];
}

int main() 
{
    FaSt
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    cout << calc(0);
}

Measured memory_bytes: 3456
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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 <cctype>
#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 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)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
int main(void){
	int N;
	vector<int> c, s, f;
	cin >> N;
	for (int i = 0; i < N-1; i++){
		int _c, _s, _f;
		cin >> _c >> _s >> _f;
		c.push_back(_c);
		s.push_back(_s);
		f.push_back(_f);
	}
	int t = 0;
	for (int i = 0; i < N-1; i++)
	{
		for (int j = i; j < N-1; j++){
			if (t < s[j])
				t = s[j];
			else if(t%f[j]==0);
			else t = t + f[j] - t % f[j];
			
			t += c[j];
			// cout << "added " << c[j] << " " << (int)(t % f[j]) << endl;
			// cout << t << endl;
		}
		cout << t << endl;
		t = 0;
	}
	cout << 0 << endl;
	return 0;
}



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

int main() {
  int x,y;
  cin >> x>> y;
  if(x==1||x==3||x==5||x==7||x==8||x==10){
    if(y==1||y==3||y==5||y==7||y==8||y==10||y==12){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if(x==4||x==6||x==9){
    if(y==6||y==9||y==11){
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


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

#define INF 1<<30

vector< vector<int> > rotate(vector< vector<int> > picture) {
    int m = picture.size();
    vector< vector<int> > result(m, vector<int>(m));
    for(int i=0; i<m; i++) for(int j=0; j<m; j++) result[i][j] = picture[j][m-1-i];
    return result;
}

vector<int> check(vector< vector<int> > scene, vector< vector<int> > picture) {
    int n = scene.size();
    int m = picture.size();
    vector<int> result(2, INF);
    bool ok = false;
    for(int r=0; r<4; r++) {
        for(int i=0; i<n-m+1; i++) for(int j=0; j<n-m+1; j++) {
            ok = true;
            vector<int> first(2, INF);
            for(int y=0; y<m; y++) for(int x=0; x<m; x++) {
                if(picture[y][x] == -1) continue;
                if(first[0] == INF) {
                    first[0] = i+y+1;
                    first[1] = j+x+1;
                }
                ok &= (scene[i+y][j+x] == picture[y][x]);
            }
            if(ok)
                if((first[0] < result[0]) || (first[0] == result[0] && first[1] < result[1]))
                    result = first;
        }
        picture = rotate(picture);
    }
    return result;
}

int main()
{
    int n, m;
    while(cin>>n>>m, n|m) {
        vector< vector<int> > scene(n, vector<int>(n)), picture(m, vector<int>(m));
        for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin>>scene[i][j];
        for(int i=0; i<m; i++) for(int j=0; j<m; j++) cin>>picture[i][j];
        vector<int> ans;
        ans = check(scene, picture);
        if(ans[0] == INF) cout<<"NA"<<endl;
        else cout<<ans[1]<<" "<<ans[0]<<endl;
    }
}

Measured memory_bytes: 1352
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define mod 1000000007


int main(){
  ll n;
  cin >>n;
  string s;
  cin >>s;
  ll k;
  cin >>k;
  char res=s[k-1];
  rep(i,n){
    if(s[i]!=res)s[i]='*';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    if((a+b)%2==0){
        printf("%d\n",(a+b)/2);
    }else{
        printf("%d\n",(a+b+1)/2);
    }
    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define max(p,q)((p)>(q)?(p):(q))

int a[1010];

int main(){
	int n;
	scanf("%d",&n);
	double d[9],df=0;
	for(int i=0;i<n;i++)scanf("%d",a+i);
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		for(int j=1;j<=3;j++)d[j]+=pow(abs(a[i]-t),j);
		df=max(df,abs(a[i]-t));
	}
	for(int j=1;j<=3;j++)printf("%f\n",pow(d[j],1.0/j));
	printf("%f\n",df);
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> s >> ss;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  if(s[0]==ss[2] && s[1] == ss[1] && s[2] == ss[0]) anss = "YES";
  else anss = "NO";
  
  cout << anss << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
int h,w;

int main() {
  cin >> h >> w;
  vector<vector<char>> maze(h,vector<char>(w));
  vector<vector<int>> visited(h,vector<int>(w,-1));
  rep(i,h)rep(j,w) cin >> maze.at(i).at(j);
  vector<int> dx = {0,0,1,-1};
  vector<int> dy = {1,-1,0,0};
  queue<pp> q;
  q.push(make_pair(0,0));
  visited.at(0).at(0) = 0;
  while(!q.empty()){
    int y,x;
    tie(y,x) = q.front();
    q.pop();
    rep(i,4){
      int new_y,new_x;
      new_y = y+dy.at(i);
      new_x = x+dx.at(i);
      if(0 <= new_y && 0 <= new_x && new_y < h && new_x < w){
        //cout << new_y << " " << new_x << endl;
        if(visited.at(new_y).at(new_x) == -1 && maze.at(new_y).at(new_x) == '.'){
          visited.at(new_y).at(new_x) = visited.at(y).at(x) + 1;
          q.push(make_pair(new_y,new_x));
        }
      }
    }
  }
  if(visited.at(h-1).at(w-1) == -1) cout << -1 << endl;
  else{
    int cnt = 0;
    rep(i,h)rep(j,w){
      if(maze.at(i).at(j) == '.'){
        cnt ++;
      }
    }
    cout << cnt-1-visited.at(h-1).at(w-1) << endl;
  }

    return 0;
}



Measured memory_bytes: 256
N, Y = map(int, input().split(' '))

truth = False

for yukichi, ichiyo in [(n, m) for n in range(N+1) for m in range(N+1) if n + m <= N]:
    hideyo = N - yukichi - ichiyo
    if (hideyo >= 0 and yukichi * 10000 + ichiyo * 5000 + hideyo * 1000 == Y):
        truth = True
        break

if (truth):
    print(str(yukichi), str(ichiyo), str(hideyo))
else:
    print('-1 -1 -1')

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

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(b+1 == a)
        printf("Yay!");
    else if(a+1 == b)
        printf("Yay!");
    else if(a==b)
        printf("Yay!");
    else
        printf(":(");
    return 0;
}

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

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define ll	long long
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int gcd(int a, int b, int c) {
	return __gcd(a, __gcd(b, c)); 
}
int main() {	
	int k, sum = 0;
	cin>>k;
	for (int a = 1; a <= k; a++){
		for (int b = 1; b <= k; b++) {
			for (int c = 1; c <= k; c++) {
				sum += gcd(a, b, c);
			}
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
A = list(map(int,input().split()))
for i in range(n): A[i] -= 1
for i in range(n):
  if not A[i] > i:continue
  else:
    if A[A[i]] == i:ans += 1
print(ans)

Measured memory_bytes: 14132
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		System.out.println((y1 - y2 + x2) + " " + (x2 - x1 + y2) + " " + (y1 - y2 + x1) + " " + (x2 - x1 + y1));
	}
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
}

int main()
{
    ll X;
    cin >> X;
    ll tmp = X % 100;
    ll x = X / 100;
    if ((tmp+4)/5 <= x) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = []
for i in range(n):
    heapq.heappush(l, -a[i])
for i in range(m):
    x = -heapq.heappop(l)
    x //= 2
    heapq.heappush(l, -x)
print(-sum(l))

Measured memory_bytes: 14180
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

int main()
{
    //freopen("input.txt","r",stdin);
    int n,a,b;scanf("%d%d%d",&n,&a,&b);
    if (a>b) {puts("0");return 0;}
    if (n==1) {printf("%d\n",a==b);return 0;}
    printf("%lld\n",ll(n-2)*(b-a)+1);
    return 0;
}


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

int N, M, R;
int r[8];
long long d[200][200];
long long ans = 1e16, INF = 1e16;

void dfs(int bit, int now, long long cost){
	bool f = true;
	for(int i=0; i<R; i++){
		if(!(bit & (1<<i))){
			if(now == -1){
				dfs(bit + (1<<i), i, 0);
			}else{
				dfs(bit + (1<<i), i, cost + d[r[now]][r[i]]);
			}
			f = false;
		}
	}
	if(f && ans > cost) ans = cost;
}

int main(){
	cin >> N >> M >> R;
	for(int i=0; i<R; i++){ cin >> r[i]; r[i]--; }
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			d[i][j] = INF;
		}
	}
	for(int i=0; i<M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = c; d[b][a] = c;
	}
	for(int i=0; i<N; i++){
		for(int j=0; j<N; j++){
			for(int k=0; k<N; k++){
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	dfs(0, -1, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N;
int cnt[114514]={0};
vi a,b,c;
int main(){
	cin>>N;
	int ans=0;
	rep(i,N-1){
		int x;
		cin>>x;
		b.pb(x);
		if(i>0){
			ans+=min(b[i],b[i-1]);	
		}else{
			ans+=b[0];	
		}
	}
	ans+=b[N-2];
	cout<<ans<<endl;
}




Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int N;
string s;

int main() {
	cin >> N >> s;
	int r = 0, b = 0;
	for (int i = 0; i < N; i++) {
		(s[i] == 'R' ? r++ : b++);
	}
	cout << (r > b ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
_=gets.chomp.split(" ").map(&:to_i)
ys,ls={},[]
while l=gets
  next if l.chomp == ""
  p,y=l.chomp.split(" ").map(&:to_i)
  ls<<{y: y, p: p.to_s}
  (ys[p] ||= []) << y
end
ys.each_pair{|_,v|v.sort! if v.length > 1 }
ls.each do |x|
  puts [x[:p],ys[x[:p].to_i].bsearch_index{|yy|x[:y]<=yy}.next.to_s].map{|z|z.rjust(6,?0)}.join
end

Measured memory_bytes: 58748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    
    ll N,a;
    vector<ll> A;
    cin >> N;
    REP(i,N){
        cin >> a;
        A.push_back(a);
    }
    
    ll X=0,S=0,D=0;
    
    S = A[0]+A[1];
    REP(i,N){
        if(i==0 || i==1)continue;
        X ^= A[i];
    }
    
    if((S-X)%2==1){
        cout << -1 << endl;
        return 0;
    }
    if(S<X){
        cout << -1 << endl;
        return 0;
    }
    D = (S-X)/2;
    
    //cout << X MM D << endl;
    
    ll Ans=0;
    
    for(ll i=(1LL<<60);i>0;i>>=1LL){
        ll x = (X/i)%2;
        ll d = (D/i)%2;
        
        if(x==0){
            if(d==1){
                Ans+=i;
            }
        }
    }
    //cout << Ans << endl;
    if(Ans>A[0]){
        cout << -1 << endl;
        return 0;
    }
    
    for(ll i=(1LL<<60);i>0;i>>=1LL){
        ll x = (X/i)%2;
        ll d = (D/i)%2;
        
        if(x==1){
            if(d==1){
                cout << -1 << endl;
                return 0;
            }
            if(Ans+i<=A[0]){
                Ans+=i;
            }
        }
    }
    if(Ans==0){
        cout << -1 << endl;
    }else{
        cout << A[0]-Ans << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();
		
		int times = T/A;
		int ans = 0;
		for(int i = 1; i <= times; i++){
			ans += B;
		}
		
		System.out.println(ans);
	}
}

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

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> k(m);
    vector<vector<int>> s(m);
    vector<int> p(m);
    for(int i = 0; i < m; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            int tmp;
            cin >> tmp;
            tmp--;
            s[i].push_back(tmp);
        }
    }
    for(int i = 0; i < m; i++){
        cin >> p[i];
    }

    int ans = 0;
    
    for(int mask = 0; mask < (1 << n); mask++){
        bool check = true;
        for(int i = 0; i < m; i++){
            int cnt = 0;
            for(int j = 0; j < k[i]; j++){
                if(mask & (1 << s[i][j])){
                    cnt++;
                }
            }
            if(cnt % 2 != p[i]){
                check = false;
                break;
            }
        }
        if(check == true){
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <time.h>
#include <algorithm>
#include <iostream>
using namespace std;
#define repi(a,b) for (int i=a;i<=b;i++)
#define repj(a,b) for (int j=a;j<=b;j++)
#define oo 123456789
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define pii pair<int,int> 
#define fir first
#define sec second
#define N 200005

int n,m;
vector<int> g[N];
int can1[N],d1;
int cann[N],dn;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>n>>m;
	repi(1,m)
	{
		int x,y;
		cin>>x>>y;
		g[x].pb(y);g[y].pb(x);
	}
	
	repi(0,(int)g[1].size()-1)
		can1[++d1]=g[1][i];
	repi(0,(int)g[n].size()-1)
		cann[++dn]=g[n][i];
	
	sort(can1+1,can1+d1+1);sort(cann+1,cann+dn+1);
	
	int p=1,q=1;
	
	while (p<=d1 && q<=dn)
	{
		if (can1[p]==cann[q]) {
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
		
		if (can1[p]>cann[q]) q++;
		else p++;
	}
	
	cout<<"IMPOSSIBLE"<<endl;
	
	return 0;
}

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

#define PI 3.14159265358979323846

using namespace std;

int fr[200005] , n , x;

int main()
{
    cin >> n;
    for(int i = 1 ; i < n ; i++)
        cin >> x , ++fr[x];
    for(int i = 1 ; i <= n ; i++)
        cout << fr[i] << '\n';
    return 0;
}


Measured memory_bytes: 4404
#include <stdio.h>
int gcd(int a,int b){
    if(a==b)return a;
    if(a>b){
        int c=a;
        a=b;
        b=c;
    }
    if(b%a==0)return a;
    else return gcd(a,b%a);
}
int main(void){
   long long n,m;
   scanf("%lld%lld",&n,&m);
   char s[n+5];
   char t[m+5];
   scanf(" %s",s);
   scanf(" %s",t);
   long long x=gcd(n,m);
   for(int i=0;i<x;i++){
       if(s[(n/x)*i]!=t[(m/x)*i]){
           printf("-1\n");
           return 0;
       }
   }
   printf("%lld\n",(n/x)*m);
}

Measured memory_bytes: 256
N,M = gets.split.map(&:to_i)
rh = {}
N.times { |i| rh[i+1] = 0 }
M.times do
  ab = gets.split.map(&:to_i)
  ab.each { |i| rh[i] += 1 }
end
puts rh.sort.map { |k,v| v }

Measured memory_bytes: 1788
circumference, house_count = gets.chomp.split(" ").map(&:to_i)
houses = gets.chomp.split(" ").map(&:to_i).sort
houses << (circumference + houses[0])

l = 0
(1..house_count).each do |i|
  l = [l, (houses[i] - houses[i - 1])].max
end

puts circumference - l


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

int main() {
    int H, N, sum;
    string ans;
    cin >> H >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A.at(i);
    }
    sum = accumulate(A.begin(), A.end(), 0);
    if (sum >= H){
        ans = "Yes";
    }else{
        ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include<iomanip>

using namespace std;
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	i64 n;
	cin >> n;
	i64 ans = n * (n - 1) / 2;
	cout << ans << endl;
	return 0;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

template <ll mod> class modint
{
private:
    ll x;

public:
    modint(ll x = 0) : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) const { return modint(*this) /= rhs; }

    modint operator-() const { return modint(-x); }

    modint pow(ll n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m.x;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        ll in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<1000000007>;

map<ll, int> factorize(ll n)
{
    map<ll, int> mp;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            mp[i]++; n /= i;
        }
    }
    if (n != 1) mp[n] = 1;
    return move(mp);
}

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

    int n; cin >> n;

    vector<int> a(n);
    map<ll, int> mp;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        for (auto &e: factorize(a[i])) {
            mp[e.first] = max(mp[e.first], e.second);
        }
    }

    mint lcm = 1;
    for (auto &e: mp) {
        lcm *= mint(e.first).pow(e.second);
    }

    mint ans = 0;
    for (int i = 0; i < n; i++) {
        ans += lcm / a[i];
    }
    cout << ans << endl;
    return 0;
}

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

typedef struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
}Node;

typedef Node *NodePointer;

NodePointer minimum(NodePointer);
NodePointer root = NULL;

NodePointer createNode(void){

  NodePointer tree = malloc(sizeof(Node));
  tree->left = NULL;
  tree->right = NULL;
  tree->parent = NULL;
  tree->key = 0;

  return tree;
}

void insert(int key){

  NodePointer z = createNode();
  NodePointer x = root;
  NodePointer y = NULL;
  z->key = key;
  while(x != NULL){
    y = x;

    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NULL){
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }
}

void inorder(NodePointer T){

  if(T != NULL){
    inorder(T->left);
    printf(" %d",T->key);
    inorder(T->right);
  }
}

void preorder(NodePointer T){

  if(T != NULL){
  printf(" %d", T->key);
    preorder(T->left);
    preorder(T->right);
  }
}

NodePointer find(int k, NodePointer T){

  while(T != NULL && T->key != k){
    if(T->key > k){
      T = T->left;
    }else{
      T = T->right;
    }
  }
  return T;
}

NodePointer successor(NodePointer T){
  NodePointer x;
  if(T->right != NULL){
    return minimum(T->right);
  }
  x = T->parent;

  while(x != NULL && T == x->right){
    T = x;
    x = x->parent;
  }
  return x;
}

void delete(NodePointer T){

  NodePointer x;
  NodePointer y;

  if(T->left == NULL || T->right == NULL){ // 子がいる時
    x = T;
  }else{ // 子がいない時
    x = successor(T);
  }
  if(x->left != NULL){
    y = x->left;
  }else{
    y = x->right;
  }

  if(y != NULL){ // 子の子があるとき
    y->parent = x->parent;
  }

  if(x->parent == NULL){
    root = y;
  }else if(x == x->parent->left){
    x->parent->left = y;
  }else{
    x->parent->right = y;
  }
  if(x != T){
    T->key = x->key;
  }
}


NodePointer minimum(NodePointer T){
  while(T->left != NULL){
    T = T->left;
  }
  return T;
}

int main(){

  int i, n, x;
  char str[10];

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", str);
    if(str[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }else if(str[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0] == 'f'){
      scanf("%d", &x);
      if(find( x, root) == NULL){
	printf("no\n");
      }else{
	printf("yes\n");
      }
    }else if(str[0] == 'd'){
      scanf("%d", &x);
      delete(find(x, root));
    }else{
      continue;
    }
  }
  return 0;
}

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

int main() {
    int h, n;
    string ans = "No";
    cin >> h >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
        h -= a[i];
        if (h <= 0) {
            ans = "Yes";
            break;
        }
    }
    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 all(v) begin(v),end(v)
using ll = long long;

int main() {
  int x;cin>>x;
  int ans=1;
  for(int i=2;i<x;i++){
    int a=i*i;
    while(a<=x){
      ans=max(ans,a);
      a*=i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
a, b, c, x, y = gets.split.map(&:to_i)

if x > y
  a, b = b, a
  x, y = y, x  
end

# hnh 使わない
ans = a * x + b * y

# 少ない方 を hnh にする
tmp = x * 2 * c + (y - x) * b
ans = [ans, tmp].min

# 両方 hnh にする
tmp = y * 2 * c
ans = [ans, tmp].min

puts ans


Measured memory_bytes: 14244
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  
  
  int x, a, b; cin >> x >> a >> b;
  x -= a;
  cout << x % b << "\n";
  return 0;
}

Measured memory_bytes: 256