akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int n;
char s[200010];
int sum[200010];
void add(){
  if(s[0]=='.'){
    sum[0]=1;
  }
  else sum[0]=0;
  rep1(i,n-1){
    if(s[i]=='.'){
      sum[i]=sum[i-1]+1;
    }
    else sum[i]=sum[i-1];
  }
}
int solve(){
  int res=sum[n-1];
  rep(i,n){
    int temp=0;
    temp+=i+1-sum[i];
    temp+=sum[n-1]-sum[i];
    res=min(res,temp);
  }
  return res;
}
int main(){
  cin>>n;
  rep(i,n) cin>>s[i];
  add();
  prin(solve());
  
  return 0;
}


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

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

    int l[1010];
    for(int i = 0;i < n;i++) cin >> l[i];
    sort(l, l+n);

    int sum = 0;
    for(int i = 0;i < n-1;i++){
        sum += l[i];
    }

    if(sum > l[n-1]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import sys,bisect
sys.setrecursionlimit(15000)
n = int(sys.stdin.readline())
a = list(map(int,sys.stdin.readline().split()))
a.append(0)

st = []
ar = 0
for i in range(n+1):
  if not st:
    st.append([i,a[i]])
  elif st[-1][1] < a[i]:
    st.append([i,a[i]])
  elif st[-1][1] == a[i]:
    st.append([i,a[i]])
  elif st[-1][1] > a[i]:
    while st and st[-1][1] >= a[i]:
      j,h = st.pop()
      ar = max(ar,(i-j)*(h))
    st.append([j,a[i]])
  #print(i,ar,st)
#print(a)
print(ar)


Measured memory_bytes: 21928
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 500017;
 
int n;
pair<int, int> a[N];
 
bool read() {
    if (!(cin >> n))
        return false;
 
    for (int i = 0; i < n; ++i)
        cin >> a[i].first >> a[i].second;
 
    return true;
}
 
void solve() {
    sort(a, a + n,
        [](const pair<int, int>& a, const pair<int, int>& b) {
            return a.second < b.second;
        }
    );
 
    int r = 0;
 
    for (int i = 0; i < n; ++i)
        if ((r += a[i].first) > a[i].second) {
            cout << "No\n";
            return ;
        }
 
    cout << "Yes\n";
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
 
    while (read())
        solve();
 
    return 0;
}

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

constexpr int MOD = 1000000007;

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  long ans, pre, i;
  if (S.at(0) == T.at(0)) ans = 3, pre = 1, i = 1;
  if (S.at(0) != T.at(0)) ans = 6, pre = 2, i = 2;
  for (; i < N; i++) {
    if (S.at(i) == T.at(i)) {
      if (pre == 1) ans *= 2;
      if (pre == 2) {}
      pre = 1;
    }
    if (S.at(i) != T.at(i)) {
      if (pre == 1) ans *= 2;
      if (pre == 2) ans *= 3;
      pre = 2;
      i++;
    }
    ans %= MOD;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3632
N, M, C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
A = []
N.times do
    A << gets.split.map(&:to_i)
end
tmp = 0
ans = 0
0.upto(N - 1) { |i| 
    0.upto(M - 1) { |j|
        tmp += A[i][j] * B[j]
    }
    ans += 1 if (tmp + C) > 0
    tmp = 0
}
puts ans

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
//        long startTime = System.currentTimeMillis();
        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        scanner.close();

        int count = 0;

        for(int i=0;i<2;i++){
            if (A > B){
                count += A;
                A--;
            }else{
                count += B;
                B--;
            }
        }

        System.out.println(count);

//        System.out.println(System.currentTimeMillis() - startTime);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s,t; cin >> s >> t;
    int n=s.size(), m=t.size();
    int res=INF;
    rep(i,n-m+1){
        int tmp=0;
        string sub=s.substr(i,m);
        rep(j,m) if(sub[j]!=t[j]) tmp++;
        chmin(res,tmp);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#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)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    int n;cin>>n;
    vl a(n+1);rrep(i,n)cin>>a[i];
    vl ca=a;
    sort(ca.begin(),ca.end());
    map<ll,ll> mp;
    ll cnt=1;
    rrep(i,n){
        mp[ca[i]]=cnt++;
    }
    rrep(i,n){
        a[i]=mp[a[i]];
    }
    ll ans=0;
    rrep(i,n){
        ll need=abs(a[i]-i);
        if(need%2!=0) ans++;
    }
    ans/=2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <cstdio>

int a[15][15];

int main(void)
{
    int n, i, j, ans = 0;

    scanf("%d" ,&n);

    for (i = 1; i <= n; i++)
    {
    	int ti = i;

    	while (ti >= 10) ti /= 10;
		int first = ti, last = i % 10;

		a[first][last]++;
    }

    for (i = 1; i < 10; i++)
		for (j = 1; j < 10; j++)
            ans += a[i][j] * a[j][i];

	printf("%d" ,ans);
	return 0;
}

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

using namespace std;

vector<vector<double>> dist;

int n;
int used;
int deep;
double allans;

void dfs(double d,int bef)
{
	//cout << d << " " << bef << " " << deep << endl;
	deep++;
	if(deep>=n)
	{
	//cout << d << endl;
		allans+=d;	
		deep--;
		return;
	}
	for(int i=0;i<n;i++)
	{
		if(used&(1<<i))
			continue;
		double nxd=d+dist[i][bef];
		//cout << i << bef <<  dist[i][bef] << endl;
		used|=(1<<i);
		dfs(nxd,i);
		used&=~(1<<i);
	}
	deep--;
}

int main()
{
	cin >> n;
	vector<int> x(n),y(n);
	for(int i=0;i<n;i++)
		cin >> x[i] >> y[i];
	dist=vector<vector<double>>(n,vector<double>(n));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			dist[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
	deep=0;
	used=0;
	allans=0;
	for(int i=0;i<n;i++)
	{
		used=(1<<i);
		//cout << i << " used : " << bitset<5>(used) << " " << used <<  endl;
		deep=0;
		dfs(0,i);
	}
	double all=1;
	for(int i=1;i<=n;i++)
		all*=i;
	cout << fixed << setprecision(15) << allans/all << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m, a, b, ans[100009];
vector<int> vec[100009];
bool vis[100009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		vec[a].pb(b);
		vec[b].pb(a);
	}
	queue<int> qu;
	qu.push(1);
	vis[1] = true;
	while (!qu.empty()) {
		int cur = qu.front();
		qu.pop();
		for (int i = 0; i < (int)vec[cur].size(); i++) {
			if (!vis[vec[cur][i]]) {
				qu.push(vec[cur][i]);
				vis[vec[cur][i]] = true;
				ans[vec[cur][i]] = cur;
			}
		}
	}
	cout << "Yes\n";
	for (int i = 2; i <= n; i++) {
		cout << ans[i] << "\n";
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 10712
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = IntStream.range(0, n).map(i -> sc.nextInt()).toArray();
		sc.close();

		int count = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != i + 1 - count) {
				count++;
			}
		}
		System.out.println(count < n ? count : -1);
	}
}


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

typedef long long int ll;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    
    int n, l;
    cin >> n >> l;
    
    vector<int> a(n + 1);
    for (int i = 1; i <= n; ++i)
        a[i] = l + i - 1;
    
    int mini = numeric_limits<int>::max();
    int minIdx = -1;
    for (int i = 1; i <= n; ++i)
    {
        if (abs(a[i]) < mini)
        {
            mini = abs(a[i]);
            minIdx = i;
        }
    }
    
    int sum = 0;
    for (int i = 1; i <= n; ++i)
        sum += a[i];
    
    cout << sum - a[minIdx] << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>, greater<int> > que1;
priority_queue<int,vector<int>, greater<int> > que2;
int n,q,k,ans=1e9;
int a[2005],minn[2005],p[2005];
void clear(int opt)
{
	
	if(opt==1)
	   while(!que1.empty())
	         que1.pop();
	if(opt==2)
	   while(!que2.empty())
	         que2.pop();         
}
int minx(int a1,int b1)
{
	return a1<b1?a1:b1;
}
bool check(int t)
{
	int c=0,mes=1,ct=0;
	bool ret=0;
	for(int i=1;i<=n;i++)
	    {
	    	if(a[i]<t)
			    c=0,mes=1;
	    	if(a[i]>=t)
	    	   {
	    	   	   c++;
	    	   	   if(a[i]==t)
	    	   	      mes=0;   
	    	   }
			 if(c>=k)
			    {
			       ct++;
				   if(mes==0)
				      ret=1;  
			    }
	    }
	if(ret==1&&ct>=q)
	   ret=1;
	else
	   ret=0;       
	return ret;    
}
int main()
{
	scanf("%d%d%d",&n,&k,&q);
	for(int i=1;i<=n;i++)
	    {
	       scanf("%d",&a[i]);
	       minn[i]=a[i];
	    }
	sort(minn+1,minn+1+n);
	for(int i=1;i<=n;i++)
	    {
	    	
	    	clear(2);
	    	if(!check(minn[i]))
	    	   continue;
	    	else
			   {
			   	
			   	  for(int j=1;j<=n;j++)
			   	      {
			   	      	  if(a[j]>=minn[i])
			   	             que1.push(a[j]);				   
			   	      	  if(a[j]<minn[i])   
			   	      	     {
			   	      	     	 int sz=que1.size();
			   	      	     	 if(sz>=k)
			   	      	     	    {	
			   	      	     	    	while(!que1.empty()&&sz>=k)
			   	      	     	    	      {
			   	      	     	    	      	  sz--;
			   	      	     	    	      	  int p=que1.top();
			   	      	     	    	      	  que2.push(p);
			   	      	     	    	      	  que1.pop();
			   	      	     	    	      }	 
			   	      	     	    }
								  clear(1);  
			   	      	     } 
			   	      }
				 int sz=que1.size();		      
			   	 if(sz>=k)
			   	    { 
			   	      	while(!que1.empty()&&sz>=k)
			   	      	      {
			   	      	      	  sz--;
			   	      	     	  int p=que1.top();
			   	      	     	  que2.push(p);
			   	      	     	  que1.pop();
			   	      	      };   		         
			   	    }
				  clear(1); 
			   	  int tot=0;
			   	  while(tot<q-1)
			   	        {	
			   	        	tot++;
			   	        	que2.pop();
			   	        } 
			   	  int t=que2.top();	 	
			   	  ans=minx(t-minn[i],ans);
			   }   
	    }
	printf("%d",ans);	  
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

void dijkstra(int start, int count, int cost[][101], int fromstart[]);

int main(){
  int fare[101][101];
  int time[101][101];
  int fromstart[101];
  int n, m;
  int a, b, c, t;
  int k;
  int p, q, r;
  int i, j;

  while(1){
    /* f[^ZbgJn */
    scanf("%d %d", &n, &m);
    if(n == 0 && m == 0) break;

    /* îñÌú» */
    for(i = 1; i <= m; i++){
      for(j = 1; j <= m; j++){
	fare[i][j] = -1;
	time[i][j] = -1;
      }
    }

    /* üHÌîñðÇÝÞ */
    for(i = 0; i < n; i++){
      scanf("%d %d %d %d", &a, &b, &c, &t);
      fare[a][b] = c;
      fare[b][a] = c;
      time[a][b] = t;
      time[b][a] = t;
    }

    /* â¢í¹ðÇÝÞ */
    scanf("%d", &k);
    for(i = 0; i < k; i++){
      scanf("%d %d %d", &p, &q, &r);
      /* _CNXg@Às */
      dijkstra(p, m, (r == 0 ? fare : time), fromstart);
      /* Å¬RXgð\¦ */
      printf("%d\n", fromstart[q]);
    }
  }
  return 0;
}

void dijkstra(int start, int count, int cost[][101], int fromstart[]){
  int done[101];
  int progress = 0;
  int min, minpoint;
  int i;

  /* îñðú»·é */
  for(i = 1; i <= count; i++){
    fromstart[i] = -1;
  }
  /* o­nÜÅÌRXgÍ¾ç©É0 */
  fromstart[start] = 0;
  /* ¢mèÉ·é */
  for(i = 1; i <= count; i++) done[i] = 0;

  /* Sn_ÌRXgªÜéÜÅ±¯é */
  while(progress < count){
    /* ¢mèn_Ì¤¿RXgÅ¬Ì_ðIÔ */
    min = -1;
    for(i = 1; i <= count; i++){
      if(done[i] == 0 && fromstart[i] >= 0 &&
	 (min > fromstart[i] || min < 0)){
	min = fromstart[i];
	minpoint = i;
      }
    }
    /* Iñ¾_Ímè·é */
    done[minpoint] = 1;
    progress++;
    /* »Ì_Æ¼ÚÂÈªén_ÌRXgðXV */
    for(i = 1; i <= count; i++){
      if(cost[minpoint][i] >= 0){
	if(fromstart[i] < 0 ||
	   fromstart[i] > fromstart[minpoint] + cost[minpoint][i]){
	  fromstart[i] = fromstart[minpoint] + cost[minpoint][i];
	}
      }
    }
  }
}

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

int main(){
    long long n,a,b,c,d,e;
    cin >> n;
    long long nnum = 1e15;
    for(int i = 0; i < 5; i++){
        long long x; cin >> x;
        nnum = min(nnum, x);
    }
    long long ans = (n+nnum-1)/nnum;
    cout << 5 + (ans-1) << endl;
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    string S;
    cin >> S;
    ll cnt_b=0, ans=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='W') ans+=cnt_b;
        else cnt_b++;
    }

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

Measured memory_bytes: 640
n = int(input())
red = []
for i in range(n):
    a,b = map(int,input().split())
    red.append([a,b])
blue = []
for i in range(n):
    c,d = map(int,input().split())
    blue.append([c,d])

red.sort(key = lambda x:(x[1],x[0]))
blue.sort(key = lambda x:(x[0],x[1]))

ans = 0
for i in range(n):
    for k in range(n):
        if blue[i][0] > red[n-1-k][0] and blue[i][1] > red[n-1-k][1]:
            ans += 1
            red[n-1-k][0] = 2000
            red[n-1-k][1] = 2000
            break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(min(a,b) + min(c,d));

    return 0;
}


Measured memory_bytes: 256
loop do
  n = gets.to_i
  break if n.zero?
  s = gets.chomp.split(/\s/).map(&:to_f)
  m = s.inject(:+)/n
  d_sigma = 0.0
  s.each{ |val| d_sigma += (val-m)**2/n }
  puts Math.sqrt(d_sigma)
end

Measured memory_bytes: 8864
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    int res = 0;
    vector<vector<pair<int, int>>> vec(n);
    rep(i,n){
        ll k;
        cin >> k;
        rep(j,k){
            ll x, y;
            cin >> x >> y;
            x--;
      //      y--;
            vec[i].push_back({x, y});
        }
    }
    rep(i,(1<<n)){
        bool h = true;
        rep(j,n){
            rep(k,vec[j].size()){
                if(i&(1<<j)){
                    if(i&(1<<vec[j][k].F)){
                        if(vec[j][k].S==0){
                          //  if(i==3)cout<<"1ikko"<<" "<<j<<" "<<k<<" "<<vec[j][k].F<<endl;
                            h = false;
                            break;
                        }
                    }else{
                        if(vec[j][k].S==1){
                         //   if(i==3)cout<<"2ikko"<<" "<<j<<" "<<k<<" "<<vec[j][k].F<<endl;
                            h = false;
                            break;
                        }
                    }
                }
            }
        }
        if(h){
      //      cout<<i<<endl;
            chmax(res, __builtin_popcount(i));
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, int>;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 100005;
int n, m, l, r, c;
ll dis;
vector<P> a[MX];
priority_queue<P, vector<P>, greater<P>> qu;

int main(){
	scanf("%d%d", &n, &m);
	rep(i,m){
		scanf("%d%d%d", &l, &r, &c);
		l--; r--;
		a[l].push_back(P(c,r));
	}
	rep(i,n){
		while(!qu.empty() && qu.top().second < i) qu.pop();
		if(i && qu.empty()) return 0*puts("-1");
		dis = i ? qu.top().first : 0;
		for(P p: a[i]) qu.push(P(p.first+dis,p.second));
	}
	printf("%lld\n", dis);
}

Measured memory_bytes: 7288
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int read(){
  int x=0,f=1;
  char ch=getchar();
  while(ch<'0'||ch>'9'){
  	if(ch=='-')
    	f=-1;
  	ch=getchar();
  }
  while(ch>='0'&&ch<='9'){
    x=x*10+ch-'0';
		ch=getchar();
  }
  return x*f;
}
int n,a;
int main(){
  std::ios::sync_with_stdio(false);
  cin>>n>>a;
  if(n%500<=a)
  	cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
  return 0;
  cout<<"我永远喜欢珂朵莉.jpg";  //皮这一下我很开心
}

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

const int MOD = 1e9 + 7;

long long gcd(long long a, long long b) {
    return b ? gcd(b, a % b) : a;
}

long long pow_mod(long long x, long long n) {
    long long res = 1;
    while (n) {
        if (n & 1) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    int N;  cin >> N;
    using P = pair<long long, long long>;
    map<P, long long> mp;
    vector<long long> a(N), b(N);
    long long cnt = 0;
    for (int i = 0; i < N; ++i) {
        cin >> a[i] >> b[i];
        long long g = gcd(a[i], b[i]);
        if (a[i] == 0 && b[i] == 0) {
            cnt++;
            continue;
        }
        a[i] /= g;  b[i] /= g;
        ++mp[P(a[i], b[i])];
    }
    // DUMP(mp);

    long long ans = 1;
    for (auto e : mp) {
        // DUMP(e);
        if (mp[P(e.first.first, e.first.second)] == 0) continue;
        if (mp[P(-e.first.second, e.first.first)] != 0) {
            ans = ans * ((pow_mod(2, mp[P(e.first.first, e.first.second)]) + pow_mod(2, mp[P(-e.first.second, e.first.first)]) - 1) % MOD ) % MOD;
            mp[P(-e.first.second, e.first.first)] = 0;
        }
        else if (mp[P(e.first.second, -e.first.first)] != 0) {
            ans = ans * ((pow_mod(2, mp[P(e.first.first, e.first.second)]) + pow_mod(2, mp[P(e.first.second, -e.first.first)]) - 1) % MOD ) % MOD;
            mp[P(e.first.second, -e.first.first)] = 0;
        }
        else {
            ans = ans * pow_mod(2, mp[P(e.first.first, e.first.second)]) % MOD;
        }
    }

    ans -= 1;
    while (ans < 0) ans += MOD;
    cout << ans + cnt << endl;
}


Measured memory_bytes: 43728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>; // グラフ型
using pint = pair<int, int>;

int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    rep(i, N) cin >> A[i];
    vector<long long> B(N);
    rep(i, N) cin >> B[i];
    ll cnt = 0;
    rep(i, N)
    {
        // １の操作が行える分だけ２の操作ができる
        // A[i]  - B[i] = 1 の時は考えない
        // 理由は２の操作ができないから
        if (B[i] - A[i] >= 0)
        {
            cnt += (B[i] - A[i]) / 2;
        }
        // 2の操作は1の操作ができる分だけ行える
        // 逆に１の最大操作回数よりも大きくなるとNo
        else
        {
            cnt += (B[i] - A[i]);
        }
    }
    if (cnt >= 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

typedef pair<int,int> pii;

int N;
vector<pii> A;
int to[200001];

int main(){
  ios_base::sync_with_stdio(false);
  cin >> N;
  A.resize(N);
  for(int i=0; i<N; i++){
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(A.begin(), A.end());
  for(int i=0; i<N; i++){
    to[A[i].second] = i;
  }

  for(int i=0; i<N; i++){
    if(to[i] < N/2){
      cout << A[N/2].first << "\n";
    }
    else{
      cout << A[N/2 - 1].first << "\n";
    }
  }

  return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <list>
#define ll unsigned long long int
using namespace std;

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

int main()
{
  ll n;
  cin >> n;
  ll arr[n];
  for(ll i=0;i<n;i++)
    cin >> arr[i];
  if(n==1){
    cout << arr[0] << endl;
  }
  else{
    ll g = gcd(arr[0],arr[1]);
    ll lcm = (arr[0]/g) * arr[1];
    for(ll i=2;i<n;i++)
    {
        g = gcd(lcm,arr[i]);
        lcm = (arr[i]/g) * lcm;
    }
    cout << lcm << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i, n, k, p, win;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d%d", &k, &p);
    win = k % p;
    printf("%d\n", (win == 0) ? p : win);
  }
  return 0;
}

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

int main() {
  string N; cin >>N;
  if ((N[0]==N[1] and N[1]==N[2]) or (N[1]==N[2] and N[2]==N[3])) {
    cout <<"Yes" <<endl;
    return 0;
  }
  cout <<"No" <<endl;
  return 0;
}


Measured memory_bytes: 256
s=list(input())
num=[]
num1=1
str1="R"
for i in range(1,len(s)):
    if s[i]==str1:
        num1+=1
    else:
        num.append(num1)
        num1=1
        if str1=="R":
            str1="L"
        else:
            str1="R"
num.append(num1)
num2=-1
ans=[0]*len(s)
for i in range(len(num)//2):
    num3=num2+num[i*2]
    ans[num3]=-(num[i*2]//-2)+(num[i*2+1]//2)
    ans[num3+1]=(num[i*2]//2)-(num[i*2+1]//-2)
    num2+=num[i*2]+num[i*2+1]
print(*ans)


Measured memory_bytes: 12044
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws Exception{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int x = Integer.parseInt(line);
        System.out.println(x*x*x);
    }
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int main()
{
    while(1)
    {
        int w,h;
        string a[50];

        //input
        cin >>w >>h;
        if(w==0) break;
        rep(i,h) cin >>a[i];

        //0:??????,1:???,2:???,3:????????¨??????,-1:???????????¨??????????????????
        int bw[50][50]={0};
        rep(i,h)rep(j,w)
        {
            if(bw[i][j]==0 && a[i][j]=='.')
            {
                //BFS
                int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1};
                int vis[50][50]={0};
                queue<pi> que;
                que.push(pi(i,j));
                vis[i][j]=1;

                bool black=false, white=false;
                while(!que.empty())
                {
                    pi p=que.front();
                    que.pop();
                    //printf("ac %d,%d\n",p.fi,p.se);

                    if(a[p.fi][p.se]=='B') black=true;
                    else if(a[p.fi][p.se]=='W') white=true;
                    else
                    {
                        rep(k,4)
                        {
                            int nx=p.se+dx[k], ny=p.fi+dy[k];
                            if(0<=nx&&nx<w && 0<=ny&&ny<h)
                            {
                                if(!vis[ny][nx])
                                {
                                    vis[ny][nx]=1;
                                    que.push(pi(ny,nx));
                                }
                            }
                        }
                    }
                }

                int r=0;
                if(black) r|=1;
                if(white) r|=2;

                if(r==0) r=-1;
                //printf("(%d,%d),r=%d\n",i,j,r);

                rep(k,h)rep(l,w)
                {
                    if(vis[k][l] && a[k][l]=='.') bw[k][l]=r;
                }

            }
        }

        int p=0,q=0;
        rep(i,h)rep(j,w)
        {
            if(bw[i][j]==1) ++p;
            if(bw[i][j]==2) ++q;
        }

        printf("%d %d\n",p,q);
    }

    return 0;
}

Measured memory_bytes: 3148
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,a[maxn],ans;
map <ll,ll> p,C,V;

int main()
{
	n=read(); rep(i,1,n) a[i]=read();
	rep(i,1,n)
	{
		ll nw=1,res=1;
		for(ll j=2;j*j*j<=a[i];j++)
		{
			if(a[i]%j==0)
			{
				int cnt=0;
				while(a[i]%j==0) a[i]/=j,cnt++; cnt%=3;
				if(cnt)
				{
					nw*=pow(j,cnt);
					res*=pow(j,3-cnt);
				}
			}
		}
		ll tmp=a[i],q=sqrt(a[i]); nw*=a[i];
		if(q*q==tmp) res*=q; else res*=a[i]*a[i];
		p[nw]=res; C[nw]++;
	}
	for(map<ll,ll>::iterator it=p.begin();it!=p.end();it++)
	{
		pair <ll,ll> p2=*it;
		if(V[p2.first]||V[p2.second]||p2.first==1) continue;
		ans+=max(C[p2.first],C[p2.second]);
		V[p2.first]=1; V[p2.second]=1;
	}
	cout<<ans+(C[1]>=1)<<endl;
	return 0;
}

Measured memory_bytes: 32256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int sum=0;
	int x;
	for(int i=0;i<n;i++){
		cin >> x;
		if(x>=m)sum++;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
h = [int(_) for _ in input().split()]
dp = [0]*(N)
dp[1] = abs(h[1]-h[0])

for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))

print(dp[N-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
#define V vector
#define L long
#define W V<L>
using namespace std;L E=70,M=2e17,i,a,b;W S(V<W>p){if(!E)return{1,0};V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1)T[x[1]&1].push_back({x[0]/2,++x[1]/2});}for(L i;i<2;i++){L c=0;for(W x:T[!i])c^=(2*x[0]+x[1])%3+1;if(!c){E--;W A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p)v[0]++;W A=S(p);A[0]--;return A;}int main(){cin>>i;V<W>p(i);while(i--,cin>>a>>b)p[i]={a+M,b+M};W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
#include<stdio.h>

int main(void){
int i,k,a[10000];

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

for(k=0;k<=i-1;k++){
printf("Case %d: %d\n",k+1,a[k]);
}

return 0;
}

Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N, D, X;
    cin >> N >> D >> X;

    int sum = X;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        sum += ((D - 1) / a) + 1;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int A,B;
	cin>>A>>B;

	if(A+B >= 10){
		cout<<"error"<<endl;
	}else{
		cout<<A+B<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        String str = scan.next();
        
        int i,j=str.length();
        for(i=0;i<str.length();i++)
        {
            if(str.charAt(i)=='A')
            {
                break;
            }
        }
        
        while(j>0)
        {
            if(str.charAt(j-1)=='Z')
            {
                break;
            }
            j--;
        }
        
        System.out.println(j-i);
    }
}

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

using namespace std;

int main(){
    string s;
    cin>>s;
    int n = s.length();
    int flag = 1;
    for (int i=1; i<=(n-1)/2; i++){
        int j = (n+3)/2 + (i-1);
        if (s[i-1]==s[j-1] and s[i-1]==s[(n-1)/2-i]){
            continue;
        }
        else{
            flag = 0;
            break;
        }
    }
    if (flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

int main() {
  int X,N;
  cin >> X >> N;
  vector<int> p(N);
  bool same = false;
  int answer;
  for (int i=0; i<N; i++){
    cin >> p.at(i);
  }
  for (int i=0; ;i++){
    for (int j=0; j<N; j++){
      if((X-i) == p.at(j)){
        same = true;
      }
    }
    
    if (same == false){
      answer = X-i;
      break;
    }
    
    same = false;
    for (int j=0; j<N; j++){
      if((X+i) == p.at(j)){
        same = true;
      }
    }
    if (same == false){
      answer = X+i;
      break;
    }
    
    same = false;
  }
  cout << answer <<endl;
        
}


Measured memory_bytes: 3632
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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


int main(void) {
	string a, b, c;
	bool flag = true;
	char pos;
	int anow = 0;
	int bnow = 0;
	int cnow = 0;
	char now = 'a';

	cin >> a >> b >> c;

	while (flag) {
		switch (now) {
		case 'a':
			if (a[anow] != '\0') {
				now = a[anow];
				anow++;
			}
			else {
				cout << "A" << endl;
				flag = false;
			}
			break;
		case 'b':
			if (b[bnow] != '\0') {
				now = b[bnow];
				bnow++;
			}
			else {
				cout << "B" << endl;
				flag = false;
			}
			break;
		case 'c':
			if (c[cnow] != '\0') {
				now = c[cnow];
				cnow++;
			}
			else {
				cout << "C" << endl;
				flag = false;
			}
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

l = int(input())
m = int(input())
n = int(input())
x = int(input())

count = 0
for i in range(l + 1):
    p = 500 * i
    for j in range(m + 1):
        q = 100 * j
        for k in range(n + 1):
            r = 50 * k
            if p + q + r == x:
                count += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

// How Many Islands?(1160)
const int dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
const int dy[] = {-1, -1, 0, 1, 1, 1, 0, -1};

void solve(vector<vector<int> >&f, int x, int y)
{
	if (x < 0 || x >= (int)f[0].size() || y < 0 || y >= (int)f.size() || f[y][x] == 0)
		return;

	f[y][x] = 0;
	for (int i = 0; i < 8; ++i)
		solve(f, x+dx[i], y+dy[i]);
	return;
}

int main()
{
	int w, h;
	while (cin >> w >> h) {
		if (w == 0 && h == 0)
			break;

		vector<vector<int> > f(h, vector<int>(w));
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j)
				cin >> f[i][j];
		}

		int ans = 0;
		for (int i = 0; i < h; ++i) {
			for (int j = 0; j < w; ++j) {
				if (f[i][j]) {
					solve(f, j, i);
					++ans;
				}
			}
		}
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 0
N = int(input())
num = 0
a = 0
b = 0
ba = 0

for _ in range(N):
    x = (input())
    num = num + x.count('AB')
    if x[0] == 'B':
        b = b + 1
        if x[-1] == 'A':
            ba = ba +1
    if x[-1] == 'A':
        a = a + 1

if ba == b and a == b and a != 0:
    print(num+b-1)
elif ba == b and a == b and a == 0:
    print(num)
else:
    print(num+min(a,b))


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
int main()
{
  long X,i,gaku;
  scanf("%ld",&X);
  gaku=100;
  for(i=1;i<=1000000000000000000;i++)
  {
   gaku=gaku+gaku/100;
   if(gaku>=X)
   {
     printf("%ld",i);
     exit(0);
   } 
  }
}
   

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

int main(){
	bool a[]={1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0};
	char c;
	cin>>c;
	int n=c-'a';
	if(a[n])cout<<"vowel"<<endl;
	else cout<<"consonant"<<endl;
	return 0;
}

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

const int N = 1e6 + 6;
int prime[N];

int gcd(int a, int b){
	if(b == 0)
		return a;
	return gcd(b,a%b);
}
 
 
void sieve(){
	
	for(int i = 1; i < N; i++)
		prime[i] = i;
	
	for(int i = 2; i < N; i++){
		if(prime[i] != i)
			continue;
		
		for(int j = i*2; j < N ; j += i){
			prime[j] = i;
		}
	}
	
	
} 
 
 
int main(){
	int n;
	cin>>n;
	int arr[n + 1];
	for(int i = 0; i < n; i++)
		cin>>arr[i];
	
	sieve();
	bool present[N];
	
	for(int i = 0; i < N; i++){
		present[i] =  false;
	}
	int num;
	bool pcoprime = true;
	for(int i = 0; i < n; i++){
		num = arr[i];
		while(num != 1){
			int pf = prime[num];
			
			if(present[pf] == true){
				pcoprime = false;
				break;
			}
			present[pf] = true;
			while(num%pf==0){
				num /= pf;
			}
			
		}
	}
	
	int result = arr[0];
	for(int i = 1; i < n; i++){
		result = gcd(result, arr[i]);
	}
	
	
	
	if(pcoprime){
		cout<<"pairwise coprime\n";
	} else if(result == 1){
		cout<<"setwise coprime\n";
	} else{
		cout<<"not coprime\n";
	}
	return 0;
}

Measured memory_bytes: 12372
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void) {
  int H, W;
  cin >> H >> W;
  int board[H][W];
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      int tmp;
      cin >> tmp;
      board[h][w] = tmp;
    }
  }
  vector<string> ans;
  for (int h = 0; h < H - 1; h++) {
    for (int w = 0; w < W; w++) {
      if (board[h][w] % 2 != 0) {
        board[h][w] -= 1;
        board[h + 1][w] += 1;
        ans.push_back(to_string(h + 1) + " " + to_string(w + 1) + " " + to_string(h + 2) + " " + to_string(w + 1));
      }
    }
  }
  int h = H - 1;
  for (int w = 0; w < W - 1; w++) {
    if (board[h][w] % 2 != 0) {
      board[h][w] -= 1;
      board[h][w + 1] += 1;
      ans.push_back(to_string(h + 1) + " " + to_string(w + 1) + " " + to_string(h + 1) + " " + to_string(w + 2));
    }
  }
  cout << ans.size() << endl;
  for (auto s : ans) {
    cout << s << endl;
  }
}


Measured memory_bytes: 13812
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
	int H=0, W = 0;
	int h=0, w = 0;
	int c = 0;
	while(1){
		cin >> H >> W;
		
		if (H == 0 && W == 0){
			break;
		}
		for (h = 0; H > h; h++){
			if (h % 2 == 0){
				c = 0;
			}
			else{
				c = 1;
			}
			for (w = 0; W > w; w++){
				if (c == 0){
					cout << "#";
					c = 1;
				}
				else{
					cout << ".";
					c = 0;
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
while line = gets
  a, b, c, d, e, f = line.split.map(&:to_f)
  det = (a*e-b*d)/1000.0
  printf "%.3f %.3f\n", ((c*e-b*f)/det).round/1000.0, ((a*f-c*d)/det).round/1000.0
end

Measured memory_bytes: 8692
def li():
    return list(map(int, input().split()))


if __name__ == "__main__":
    n = int(input())
    [ga, sa, ba] = li()
    [gb, sb, bb] = li()

    # A->Bでのトレード成果
    # ga, sa, baの中で最大効率を探して、割り切れる範囲で先に進めてしまう
    # gaが最大効率なら(n//ga - 1)*gaまではgを買ったことにすればいい
    # r_g = gb / ga
    # r_s = sb / sa
    # r_b = bb / ba
    # if (n // ga - 5000) > 0 and r_g >= 1 and r_g >= r_s and r_g >= r_b:
    #     skip = (n // ga - 5000) * ga
    #     dp = [gb * skip] * (n + 1 - skip)
    # elif (n // sa - 5000) > 0 and r_s >= 1 and r_s >= r_g and r_s >= r_b:
    #     skip = (n // sa - 5000) * sa
    #     dp = [sb * skip] * (n + 1 - skip)
    # elif (n // ba - 5000) > 0 and r_b >= 1 and r_b >= r_g and r_b >= r_s:
    #     skip = (n // ba - 5000) * ba
    #     dp = [bb * skip] * (n + 1 - skip)
    # else:
    #     skip = n - 1
    #     dp = [n - 1] * 2
    dp = [0] * (n + 1)

    for i in range(1, len(dp)):
        g_trade = dp[i - ga] + gb if i - ga >= 0 else dp[i - 1]
        s_trade = dp[i - sa] + sb if i - sa >= 0 else dp[i - 1]
        b_trade = dp[i - ba] + bb if i - ba >= 0 else dp[i - 1]
        dp[i] = max(dp[i - 1] + 1, g_trade, s_trade, b_trade)
    # print(dp)
    a_result = dp[-1]

    # B->Aでのトレード成果
    # r_g = ga / gb
    # r_s = sa / sb
    # r_b = ba / bb
    # skip_num = 5000
    # if (a_result // gb - 1) > 0 and r_g >= 1 and r_g >= r_s and r_g >= r_b:
    #     skip_num = max(sb // gb + 1, bb // gb + 1)*2
    #     skip = max((a_result // gb - skip_num), 0) * gb
    #     dp = [ga * skip] * (a_result + 1 - skip)
    # elif (a_result // sb - 1) > 0 and r_s >= 1 and r_s >= r_g and r_s >= r_b:
    #     skip_num = max(gb // sb + 1, bb // sb + 1)*2
    #     skip = max((a_result // sb - skip_num), 0) * sb
    #     dp = [sa * skip] * (a_result + 1 - skip)
    # elif (a_result // bb - 1) > 0 and r_b >= 1 and r_b >= r_g and r_b >= r_s:
    #     skip_num = max(sb // bb + 1, gb // bb + 1)*2
    #     skip = max((a_result // bb - skip_num), 0) * bb
    #     dp = [ba * skip] * (a_result + 1 - skip)
    # else:
    #     skip = a_result - 1
    #     dp = [a_result - 1] * 2
    dp = [0] * (a_result + 1)

    for i in range(1, len(dp)):
        g_trade = dp[i - gb] + ga if i - gb >= 0 else dp[i - 1]
        s_trade = dp[i - sb] + sa if i - sb >= 0 else dp[i - 1]
        b_trade = dp[i - bb] + ba if i - bb >= 0 else dp[i - 1]
        dp[i] = max(dp[i - 1] + 1, g_trade, s_trade, b_trade)
    # print(dp)
    print(dp[-1])

# n+1個のドングリを取引にかけたときに得られるドングリポテンシャルは
# n個までの最適+1, n-gA個までの最適+gB, n-sA個までの最適+sB, n-bA個までの最適+bBで一番大きくなる値

# AでBより安く金属を手に入れる
# Bでドングリに戻して、Aより安く金属を手に入れる
# Aでドングリに戻して帰る


Measured memory_bytes: 230424
#include<iostream>
#include<string>
#include<map>
#include<set>
#include<sstream>
#include<vector>

using namespace std;

typedef vector< vector<int> > Graph;

#define N 3000

int cnt = 0;
bool vis[N];
map<string,int> D;
map<int,string> revD;
set<string> Groups;

void dfs(const Graph &G ,string cur){
  //cout << st << ' ' << revD[st] << ' ' << G[st].size() << endl;
  int v = D[cur];
  if(Groups.find(cur)==Groups.end())++cnt;
  for(int i = 0; i < (int)G[v].size(); ++i){
    if( !vis[G[v][i]] ){
      vis[G[v][i]]=true;
      dfs(G,revD[G[v][i]]);
    }
  }
}

int main()
{
  while(true){
    int id = 0;
    Graph G(N);
    int n;

    D.clear();
    revD.clear();
    Groups.clear();
    cnt=0;
    fill(vis,vis+N,false);
    cin >> n;
    if(n==0)break;

    string g1;
    for(int i = 0; i < n; ++i){
      string line;
      cin >> line;
      for(int j = 0; j < (int)line.length(); ++j){
	if(line[j]==':')line[j]=' ';
	if(line[j]==',')line[j]=' ';
	if(line[j]=='.')line[j]=' ';
      }
      istringstream iss(line);
      string group;

      iss >> group;
      //cout << "Group : " << group << endl;

      D[group]=id;
      revD[id]=group;
      Groups.insert(group);
      ++id;

      if(i==0)g1=group;
      while(iss){
	string tmp;
	iss >> tmp;
	if(tmp.length()>0){
	  if(D.find(tmp)==D.end()){
	    D[tmp]=id;
	    revD[id]=tmp;
	    ++id;
	  }
	  G[D[group]].push_back(D[tmp]);
	  //cout << "Added : " << D[tmp] << ' ' << revD[id] << endl;
	}
      }

      //cout << G[D[group]].size() << endl;
    }

    dfs(G,g1);
    cout << cnt << endl;
    //return 0;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>

 

using namespace std;

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= a && a <= c )
        cout << b << " " << a << " " << c << endl;
    else if (b <= c && c <= a )
        cout << b << " " << c << " " << a << endl;
    else if (c <= b && b <= a )
        cout << c << " " << b << " " << a << endl;
    else 
        cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 3056
import sys

input = sys.stdin.readline

N = int(input().rstrip())
S = []
for s in range(N):
    S.append(sorted(input().rstrip()))
S = sorted(S)
ans = 0
ren = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        ans += ren
        ren += 1
    else:
        ren = 1

print(ans)


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

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

  int n, k; cin >> n >> k;
  ll now = 1;
  for(int i=0;i<n;++i) {
    now = min(now * 2, now + k);
  }
  cout << now << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <math.h>
const int INF=1001001001;
const double PI=3.14159265;


int main() {
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double x=h*30*M_PI/180+0.5*m*M_PI/180;
    double y=m*6*M_PI/180;
    //double x=h*60*60*M_PI/21600;
    //double y=m*60*M_PI/1800;
    double sa=y-x;
    long double c=sqrt(a*a+b*b-2*a*b*cos(y-x));
      cout << fixed << setprecision(30);
  
  cout<<c<<endl;
    
}

Measured memory_bytes: 4216
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;

#include <algorithm>

//0-indexed overflow-> max:Height*MOD sum's comment out:2*MOD
template <class T, int SIZE>
struct BinaryIndexedTree {
    T seg[SIZE];
    
    inline void init() {
        fill_n(seg, SIZE, 0);
    }

    inline void add(uint i, T x) {
        while (i < SIZE) {
            seg[i] += x;
            i += (i+1) & ~i;
        }
    }
    //[0, i)
    inline T sum(uint i) {
        T s = 0;
        uint d = 1;
        while (i >= d) {
            i -= d;
            s += seg[i];
            d = (i+1) & ~i;
        }
        return s;
    }
    //[a, b)
    inline T sum(uint a, uint b) {
        T d = sum(b) - sum(a);
        return d;
    }
};
typedef long long ll;
typedef pair<int, int> P;

const int MN = 100100;
BinaryIndexedTree<int, MN> b;
int main() {
    b.init();
    int n, m;
    cin >> n >> m;
    for (int i = 1; i < MN; i++) {
        if (i*2 <= m) {
            b.add(max(0, i), 1);
            continue;
        }
        if (m <= i) {
            break;
        }
        int u = m-i;
        for (int j = i; j < MN; j += i) {
            b.add(max(i, j-u), 1);
            b.add(max(i, j), -1);
        }
    }
    for (int i = 1; i <= n-m+1; i++) {
        printf("%d", b.sum(i)+m);
        if (i < n-m+1) {
            printf(" ");
        } else {
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1532